From 35c6594a52642e890f7de1dfe24da6d5d70d8f4b Mon Sep 17 00:00:00 2001 From: Jaapio Date: Sun, 30 Apr 2017 17:20:38 +0200 Subject: [PATCH] Allow fqsen with utf-8 chars Be more specific when checking the first character of the element names. And allow utf-8 chars in element names according to the php spec. Fixes #7. --- README.md | 1 + src/Fqsen.php | 6 +++++- tests/unit/FqsenTest.php | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 52b12bc..68a80c8 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # ReflectionCommon +[![Build Status](https://travis-ci.org/phpDocumentor/ReflectionCommon.svg?branch=master)](https://travis-ci.org/phpDocumentor/ReflectionCommon) diff --git a/src/Fqsen.php b/src/Fqsen.php index c7be3f1..ce88d03 100644 --- a/src/Fqsen.php +++ b/src/Fqsen.php @@ -38,7 +38,11 @@ final class Fqsen public function __construct($fqsen) { $matches = array(); - $result = preg_match('/^\\\\([\\w_\\\\]*)(?:[:]{2}\\$?([\\w_]+))?(?:\\(\\))?$/', $fqsen, $matches); + $result = preg_match( + '/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/', + $fqsen, + $matches + ); if ($result === 0) { throw new \InvalidArgumentException( diff --git a/tests/unit/FqsenTest.php b/tests/unit/FqsenTest.php index 38c7680..aa1065d 100644 --- a/tests/unit/FqsenTest.php +++ b/tests/unit/FqsenTest.php @@ -43,6 +43,7 @@ public function validFqsenProvider() ['\My\Space\MY_CONSTANT2', 'MY_CONSTANT2'], ['\My\Space\MyClass', 'MyClass'], ['\My\Space\MyInterface', 'MyInterface'], + ['\My\Space\Option«T»', 'Option«T»'], ['\My\Space\MyTrait', 'MyTrait'], ['\My\Space\MyClass::myMethod()', 'myMethod'], ['\My\Space\MyClass::$my_property', 'my_property'], @@ -72,6 +73,7 @@ public function invalidFqsenProvider() ['\My\*'], ['\My\Space\.()'], ['My\Space'], + ['1_function()'] ]; }