Skip to content

Commit

Permalink
#60 Fixed issue with disabled rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Horn committed Jul 5, 2017
1 parent 807d2ec commit 15c0a96
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
26 changes: 24 additions & 2 deletions Helper/Strategy/RegExAllMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
class RegExAllMatcher implements StrategyInterface
{
/*
* Rewrite
*/
const REWRITE_DISABLED_URL_PREFIX = '/index.php';

/**+
* @var string
*/
Expand Down Expand Up @@ -45,7 +50,15 @@ public function getName()
*/
public function isMatch($url, WhitelistEntry $rule)
{
return (\preg_match(\sprintf('#^.*%s/?.*$#i', $this->quoteRule($rule->getUrlRule())), $url) === 1);
return (
preg_match(
sprintf(
'#^.*%s/?.*$#i',
$this->quoteRule($rule->getUrlRule())
),
$this->getCleanUrl($url)
) === 1
);
}

/**
Expand All @@ -56,6 +69,15 @@ public function isMatch($url, WhitelistEntry $rule)
*/
private function quoteRule($rule, $delimiter = '#')
{
return \str_replace($delimiter, \sprintf('\%s', $delimiter), $rule);
return str_replace($delimiter, \sprintf('\%s', $delimiter), $rule);
}

/**
* @param $url
* @return string
*/
private function getCleanUrl($url)
{
return str_replace(self::REWRITE_DISABLED_URL_PREFIX, '', $url);
}
}
16 changes: 15 additions & 1 deletion Helper/Strategy/StaticMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
class StaticMatcher implements StrategyInterface
{
/*
* Rewrite
*/
const REWRITE_DISABLED_URL_PREFIX = '/index.php';

/**+
* @var string
*/
Expand Down Expand Up @@ -45,6 +50,15 @@ public function getName()
*/
public function isMatch($url, WhitelistEntry $rule)
{
return ($url === $rule->getUrlRule());
return ($this->getCleanUrl($url) === $rule->getUrlRule());
}

/**
* @param $url
* @return string
*/
private function getCleanUrl($url)
{
return str_replace(self::REWRITE_DISABLED_URL_PREFIX, '', $url);
}
}
7 changes: 7 additions & 0 deletions Test/Unit/Helper/Strategy/RegExAllMatcherUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public function matchStaticRulesCorrectly()
$this->assertTrue($matcher->isMatch('/foobar/', $rule));
$this->assertTrue($matcher->isMatch('/foobar/baz', $rule));
$this->assertTrue($matcher->isMatch('/foobar/baz/', $rule));
// without rewrite
$this->assertFalse($matcher->isMatch('/index.php', $rule));
$this->assertFalse($matcher->isMatch('/index.php/', $rule));
$this->assertTrue($matcher->isMatch('/index.php/foobar', $rule));
$this->assertTrue($matcher->isMatch('/index.php/foobar/', $rule));
$this->assertTrue($matcher->isMatch('/index.php/foobar/baz', $rule));
$this->assertTrue($matcher->isMatch('/index.php/foobar/baz/', $rule));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Test/Unit/Helper/Strategy/StaticMatcherUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ public function matchStaticRulesCorrectly()
// simple
$this->assertTrue($matcher->isMatch('/foobar', $rule));
$this->assertFalse($matcher->isMatch('/bar', $rule));
// without rewrite
$this->assertTrue($matcher->isMatch('/index.php/foobar', $rule));
$this->assertFalse($matcher->isMatch('/index.php/bar', $rule));
}
}
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ services:
- 8000:80
networks: &appnetworks
- www
environment:
- APP_MAGE_MODE=developer

phpfpm:
image: mageinferno/magento2-php:7.0-fpm-1
links:
- db
volumes: *appvolumes
networks: *appnetworks
environment:
- PHP_MEMORY_LIMIT=4096M
- APP_MAGE_MODE=developer

db:
image: percona:5.7
Expand Down

0 comments on commit 15c0a96

Please sign in to comment.