Skip to content

Commit

Permalink
Merge pull request #76 from bitExpert/fix/75_strategy_static
Browse files Browse the repository at this point in the history
#75 Static matcher now canonicalizes url and rule to omit differences…
  • Loading branch information
websharp committed Jul 11, 2017
2 parents e51140e + 7e9fcd3 commit dc623ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- #74 Provides backwards compatibility by set strategy for existing rules to regex matcher instead of static
- #72 Fixes on class resolution

Expand Down
18 changes: 14 additions & 4 deletions Helper/Strategy/StaticMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,'/') . '/';
}
}
4 changes: 4 additions & 0 deletions Test/Unit/Helper/Strategy/StaticMatcherUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit dc623ef

Please sign in to comment.