diff --git a/src/NamedParameter.php b/src/NamedParameter.php index c06b9075..9a4de633 100644 --- a/src/NamedParameter.php +++ b/src/NamedParameter.php @@ -844,7 +844,7 @@ public function getMatchPattern() if ($this->validationPattern) { $pattern = $this->validationPattern; } elseif ($enum = $this->getEnum()) { - $pattern = '^(' . implode('\|', array_map('preg_quote', $enum)) . ')$'; + $pattern = '^(' . implode('|', array_map('preg_quote', $enum)) . ')$'; } else { switch ($this->getType()) { case self::TYPE_NUMBER: diff --git a/src/Resource.php b/src/Resource.php index a36ccbd3..8851f0ce 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -200,11 +200,11 @@ public function matchesUri($uri) if ('^' === $matchPattern[0]) { $matchPattern = substr($matchPattern, 1); } - + if ('$' === substr($matchPattern, -1)) { $matchPattern = substr($matchPattern, 0, -1); } - + $regexUri = str_replace( '/{'.$uriParameter->getKey().'}', '/'.$matchPattern, @@ -221,7 +221,7 @@ public function matchesUri($uri) $regexUri = preg_replace('/\/{.*}/U', '\/([^/]+)', $regexUri); $regexUri = preg_replace('/\/~{.*}/U', '\/([^/]*)', $regexUri); - $regexUri = '|^' . $regexUri . '$|'; + $regexUri = chr(128).'^'.$regexUri.'$'.chr(128); return (bool) preg_match($regexUri, $uri); } diff --git a/test/NamedParameters/UriParameterTest.php b/test/NamedParameters/UriParameterTest.php index 00de4ea0..689e8513 100644 --- a/test/NamedParameters/UriParameterTest.php +++ b/test/NamedParameters/UriParameterTest.php @@ -60,4 +60,26 @@ public function shouldCorrectlyParseRegexUriParameters() $resource = $apiDef->getResourceByUri('/user/alec'); $this->assertInstanceOf('\Raml\Resource', $resource); } + + /** @test */ + public function shouldCorrectlyParseEnumUriParameters() + { + $raml = <<parser->parseFromString($raml, ''); + $resource = $apiDef->getResourceByUri('/user/one'); + $this->assertInstanceOf('\Raml\Resource', $resource); + } }