Skip to content

Commit

Permalink
fix too strict regular expression when determining if the definition is
Browse files Browse the repository at this point in the history
a domain, fixes Jalle19#2
  • Loading branch information
Jalle19 committed May 11, 2014
1 parent 7ee6733 commit 23723dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Whitelist/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function whitelist(array $whitelist)
elseif (preg_match('/^[0-9a-f:\/]+$/', $definition))
$definitionObject = new Definition\IPv6CIDR($definition);
// Wildcard domain
elseif (preg_match('/^\*\.[\w\.]+$/', $definition))
elseif (preg_match('/^\*\.[\w\.\-]+$/', $definition))
$definitionObject = new Definition\WildcardDomain($definition);
// Domain
elseif (preg_match('/^[\w\.]+$/', $definition))
elseif (preg_match('/^[\w\.\-]+$/', $definition))
$definitionObject = new Definition\Domain($definition);
else
throw new \InvalidArgumentException('Unable to parse definition "'.$definition.'"');
Expand Down
6 changes: 6 additions & 0 deletions tests/CheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function testUnknownDefinition()
}

/**
* This test also tests that the whitelist definitions are valid, ie. they
* don't throw an exception
* @dataProvider matchDataprovider
*/
public function testMatch($expected, $expression)
Expand All @@ -56,6 +58,8 @@ public function testMatch($expected, $expression)
'2001:14d8:100:934b::3:1',
'2001:14b8:100:934b::/64',
'test.com',
'example-domain.com',
'*.another-example-domain.com',
'*.example.com',
new Whitelist\Definition\Domain('sub.example.com'),
));
Expand All @@ -78,6 +82,8 @@ public function matchDataProvider()
array(true, 'anything.goes.example.com'),
array(true, 'sub.example.com'),
array(false, 'test.example2.com'),
array(true, 'example-domain.com'),
array(true, 'test.another-example-domain.com')
);
}

Expand Down

0 comments on commit 23723dc

Please sign in to comment.