From 23723dc413fc36a7912323d3c1855bb1f5baef3a Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Sun, 11 May 2014 19:35:28 +0300 Subject: [PATCH] fix too strict regular expression when determining if the definition is a domain, fixes #2 --- src/Whitelist/Check.php | 4 ++-- tests/CheckTest.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Whitelist/Check.php b/src/Whitelist/Check.php index 1a4363c..82179c7 100644 --- a/src/Whitelist/Check.php +++ b/src/Whitelist/Check.php @@ -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.'"'); diff --git a/tests/CheckTest.php b/tests/CheckTest.php index 572b256..22dc682 100644 --- a/tests/CheckTest.php +++ b/tests/CheckTest.php @@ -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) @@ -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'), )); @@ -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') ); }