Fix for pure URL fragment getting Url prepended - #701

This commit is contained in:
Andy Miller
2016-02-24 14:45:57 -07:00
parent 89fbd4c2bf
commit f74562987d
2 changed files with 19 additions and 22 deletions

View File

@@ -746,18 +746,18 @@ class Uri
$url_path = $url;
}
$external = false;
$base = $grav['base_url_relative'];
$base_url = rtrim($base . $grav['pages']->base(), '/') . $language_append;
$pages_dir = $grav['locator']->findResource('page://');
$external = false;
$base = $grav['base_url_relative'];
$base_url = rtrim($base . $grav['pages']->base(), '/') . $language_append;
$pages_dir = $grav['locator']->findResource('page://');
// if absolute and starts with a base_url move on
if (isset($url['scheme']) && Utils::startsWith($url['scheme'], 'http')) {
$external = true;
} elseif (($base_url != '' && Utils::startsWith($url_path, $base_url)) ||
$url_path == '/' ||
Utils::startsWith($url_path, '#')) {
$url_path = $base_url . $url_path;
} elseif ($url_path == '' && isset($url['fragment'])) {
$external = true;
} elseif (($base_url != '' && Utils::startsWith($url_path, $base_url)) || $url_path == '/') {
$url_path = $base_url . $url_path;
} else {
// see if page is relative to this or absolute

View File

@@ -228,7 +228,7 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->parsedown->text('[With Query](?foo=bar)'));
$this->assertSame('<p><a href="/foo:bar">With Param</a></p>',
$this->parsedown->text('[With Param](/foo:bar)'));
$this->assertSame('<p><a href="/#foo">With Anchor</a></p>',
$this->assertSame('<p><a href="#foo">With Anchor</a></p>',
$this->parsedown->text('[With Anchor](#foo)'));
$this->config->set('system.languages.supported', ['fr','en']);
@@ -244,7 +244,7 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->parsedown->text('[With Query](?foo=bar)'));
$this->assertSame('<p><a href="/fr/foo:bar">With Param</a></p>',
$this->parsedown->text('[With Param](/foo:bar)'));
$this->assertSame('<p><a href="/fr/#foo">With Anchor</a></p>',
$this->assertSame('<p><a href="#foo">With Anchor</a></p>',
$this->parsedown->text('[With Anchor](#foo)'));
}
@@ -256,7 +256,7 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->grav['language'] = new Language($this->grav);
$this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
$this->assertSame('<p><a href="/fr/item2/item2-2#foo">Current Anchor</a></p>',
$this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="/fr/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
@@ -275,12 +275,12 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->grav['language'] = new Language($this->grav);
$this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
$this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-1#foo">Peer Anchor</a></p>',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-2#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev/fr/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
@@ -320,7 +320,7 @@ class ParsedownTest extends \Codeception\TestCase\Test
{
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="/item2/item2-2#foo">Current Anchor</a></p>',
$this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
@@ -335,19 +335,16 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->config->set('system.absolute_urls', true);
$this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
$this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev/item2/item2-1#foo">Peer Anchor</a></p>',
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="http://testing.dev/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="http://testing.dev/item2/item2-2#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
}
public function testAnchorLinksWithPortAbsoluteUrls()
{
$this->config->set('system.absolute_urls', true);
@@ -357,7 +354,7 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="http://testing.dev:8080/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="http://testing.dev:8080/item2/item2-2#foo">Current Anchor</a></p>',
$this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev:8080/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
@@ -371,7 +368,7 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="/subdir/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="/subdir/item2/item2-2#foo">Current Anchor</a></p>',
$this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="/subdir/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));
@@ -386,7 +383,7 @@ class ParsedownTest extends \Codeception\TestCase\Test
$this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1#foo">Peer Anchor 2</a></p>',
$this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2#foo">Current Anchor</a></p>',
$this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
$this->parsedown->text('[Current Anchor](#foo)'));
$this->assertSame('<p><a href="http://testing.dev/subdir/#foo">Root Anchor</a></p>',
$this->parsedown->text('[Root Anchor](/#foo)'));