From eba2544fdc62f3d2341c2c8ddc5fc6d22745444c Mon Sep 17 00:00:00 2001 From: Daniel Leech Date: Sun, 27 Jan 2019 14:35:13 +0000 Subject: [PATCH] remove fragments --- CHANGELOG.md | 4 ++++ lib/Model/Url.php | 5 +++++ tests/Unit/Model/UrlTest.php | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f6a0f1..8d04d5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [Unreleased] + +- Unconditionally remove URL fragments. + ## [0.2.1] - 2019-01-26 - Use correct autoload path when included as a dependency diff --git a/lib/Model/Url.php b/lib/Model/Url.php index 7e50504..db7247e 100644 --- a/lib/Model/Url.php +++ b/lib/Model/Url.php @@ -82,6 +82,11 @@ public function resolveUrl($link): self $link = $link->withPort($this->uri->getPort()); } + if ($link->getFragment()) { + // unconditionally remove fragments + $link = $link->withFragment(''); + } + return new self($link, $this, $this->distance + 1); } diff --git a/tests/Unit/Model/UrlTest.php b/tests/Unit/Model/UrlTest.php index 48b550c..0a961b8 100644 --- a/tests/Unit/Model/UrlTest.php +++ b/tests/Unit/Model/UrlTest.php @@ -98,6 +98,12 @@ public function provideResolve() 'templates.html', 'https://example.com:1234/templates.html' ]; + + yield 'ignores fragments' => [ + 'https://example.com', + '#foobar', + 'https://example.com' + ]; } public function testIsHttp()