]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fix: return the proper value for the "self" feed attribute 662/head
authorVirtualTam <virtualtam@flibidi.net>
Sun, 16 Oct 2016 18:52:35 +0000 (20:52 +0200)
committerVirtualTam <virtualtam@flibidi.net>
Sun, 16 Oct 2016 18:58:15 +0000 (20:58 +0200)
Fixes https://github.com/shaarli/Shaarli/issues/629
Closes https://github.com/shaarli/Shaarli/pull/630

Note: you might need to empty the "pagecache" directory for the
fix to be taken into account

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
application/FeedBuilder.php
tests/FeedBuilderTest.php

index 58c6bb179a636688a648bab720e43930306d5f1a..c6657fbb483215074a4bd5ce5cb57adf6a4276ff 100644 (file)
@@ -124,7 +124,8 @@ class FeedBuilder
         $data['last_update'] = $this->getLatestDateFormatted();
         $data['show_dates'] = !$this->hideDates || $this->isLoggedIn;
         // Remove leading slash from REQUEST_URI.
-        $data['self_link'] = $pageaddr . escape(ltrim($this->serverInfo['REQUEST_URI'], '/'));
+        $data['self_link'] = escape(server_url($this->serverInfo))
+                           . escape($this->serverInfo['REQUEST_URI']);
         $data['index_url'] = $pageaddr;
         $data['usepermalinks'] = $this->usePermalinks === true;
         $data['links'] = $linkDisplayed;
index c9ff397d153e928c87ef1276f22307af62b63607..aa57f44e7c30c5b0dce249aeabb1bcdcdbe78b3d 100644 (file)
@@ -217,4 +217,37 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
         $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
         $this->assertEquals('http://pubsubhub.io', $data['pubsubhub_url']);
     }
+
+    /**
+     * Test buildData when Shaarli is served from a subdirectory
+     */
+    public function testBuildDataServerSubdir()
+    {
+        $serverInfo = array(
+            'HTTPS' => 'Off',
+            'SERVER_NAME' => 'host.tld',
+            'SERVER_PORT' => '8080',
+            'SCRIPT_NAME' => '/~user/shaarli/index.php',
+            'REQUEST_URI' => '/~user/shaarli/index.php?do=feed',
+        );
+        $feedBuilder = new FeedBuilder(
+            self::$linkDB,
+            FeedBuilder::$FEED_ATOM,
+            $serverInfo,
+            null,
+            false
+        );
+        $feedBuilder->setLocale(self::$LOCALE);
+        $data = $feedBuilder->buildData();
+
+        $this->assertEquals(
+            'http://host.tld:8080/~user/shaarli/index.php?do=feed',
+            $data['self_link']
+        );
+
+        // Test first link (note link)
+        $link = array_shift($data['links']);
+        $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['guid']);
+        $this->assertEquals('http://host.tld:8080/~user/shaarli/?WDWyig', $link['url']);
+    }
 }