From 6f061d9a827886605e3815f8625766c9ec911f8d Mon Sep 17 00:00:00 2001 From: Florian Horn Date: Tue, 11 Jul 2017 09:09:10 +0200 Subject: [PATCH] #75 Static matcher now canonicalizes url and rule to omit differences of trailing slashes --- Changelog.md | 1 + Helper/Strategy/StaticMatcher.php | 18 ++++++++++++++---- .../Helper/Strategy/StaticMatcherUnitTest.php | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 8af0313..7a550d7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed +- #75 Static matcher now canonicalizes url and rule to omit differences of trailing slashes - #72 Fixes on class resolution ## 2.0.2 diff --git a/Helper/Strategy/StaticMatcher.php b/Helper/Strategy/StaticMatcher.php index 43a9de0..06fd91b 100644 --- a/Helper/Strategy/StaticMatcher.php +++ b/Helper/Strategy/StaticMatcher.php @@ -50,15 +50,25 @@ public function getName() */ public function isMatch($url, WhitelistEntry $rule) { - return ($this->getCleanUrl($url) === $rule->getUrlRule()); + return ($this->getCanonicalUrl($url) === $this->getCanonicalRule($rule->getUrlRule())); } /** - * @param $url + * @param string $url * @return string */ - private function getCleanUrl($url) + private function getCanonicalUrl($url) { - return str_replace(self::REWRITE_DISABLED_URL_PREFIX, '', $url); + $canonicalUrl = rtrim($url,'/') . '/'; + return str_replace(self::REWRITE_DISABLED_URL_PREFIX, '', $canonicalUrl); + } + + /** + * @param string $rule + * @return string + */ + private function getCanonicalRule($rule) + { + return rtrim($rule,'/') . '/'; } } diff --git a/Test/Unit/Helper/Strategy/StaticMatcherUnitTest.php b/Test/Unit/Helper/Strategy/StaticMatcherUnitTest.php index fc38aaa..660fd3d 100644 --- a/Test/Unit/Helper/Strategy/StaticMatcherUnitTest.php +++ b/Test/Unit/Helper/Strategy/StaticMatcherUnitTest.php @@ -40,9 +40,13 @@ public function matchStaticRulesCorrectly() */ // simple $this->assertTrue($matcher->isMatch('/foobar', $rule)); + $this->assertTrue($matcher->isMatch('/foobar/', $rule)); $this->assertFalse($matcher->isMatch('/bar', $rule)); + $this->assertFalse($matcher->isMatch('/bar/', $rule)); // without rewrite $this->assertTrue($matcher->isMatch('/index.php/foobar', $rule)); + $this->assertTrue($matcher->isMatch('/index.php/foobar/', $rule)); $this->assertFalse($matcher->isMatch('/index.php/bar', $rule)); + $this->assertFalse($matcher->isMatch('/index.php/bar/', $rule)); } }