Skip to content

Commit

Permalink
Fix scoping of namespaces which have a dash in their namespace for st…
Browse files Browse the repository at this point in the history
…ring literals (#211)

Closes #210
  • Loading branch information
theofidry authored May 29, 2018
1 parent 91fae9c commit 83b9abb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions specs/string-literal/array-var.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
<?php
$x = [
'Symfony\\Component\\Yaml\\Yaml' => 'Symfony\\Component\\Yaml\\Yaml',
'\\Symfony\\Component\\Yaml\\Yaml' => '\\Symfony\\Component\\Yaml\\Yaml',
'Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\Yaml',
'\\Humbug\\Symfony\\Component\\Yaml\\Yaml' => '\\Humbug\\Symfony\\Component\\Yaml\\Yaml',
'Symfony\\Component\\Yaml\\Yaml' => 'Symfony\\Component\\Yaml\\_Yaml',
'\\Symfony\\Component\\Yaml\\Yaml' => '\\Symfony\\Component\\Yaml\\_Yaml',
'Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\_Yaml',
'\\Humbug\\Symfony\\Component\\Yaml\\Yaml' => '\\Humbug\\Symfony\\Component\\Yaml\\_Yaml',
];
----
<?php
namespace Humbug;
$x = ['Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\Yaml', 'Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\Yaml', 'Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\Yaml', 'Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\Yaml'];
$x = ['Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\_Yaml', 'Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\_Yaml', 'Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\_Yaml', 'Humbug\\Symfony\\Component\\Yaml\\Yaml' => 'Humbug\\Symfony\\Component\\Yaml\\_Yaml'];

PHP
,
Expand Down
16 changes: 8 additions & 8 deletions specs/string-literal/class-const.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<?php
class Foo {
const X = 'Symfony\\Component\\Yaml\\Yaml';
const X = '\\Symfony\\Component\\Yaml\\Yaml';
const X = 'Humbug\\Symfony\\Component\\Yaml\\Yaml';
const X = '\\Humbug\\Symfony\\Component\\Yaml\\Yaml';
const X = 'Symfony\\Component\\Yaml\\Ya_ml';
const X = '\\Symfony\\Component\\Yaml\\Ya_ml';
const X = 'Humbug\\Symfony\\Component\\Yaml\\Ya_ml';
const X = '\\Humbug\\Symfony\\Component\\Yaml\\Ya_ml';
const X = 'HelloWorld';
}
Expand All @@ -39,10 +39,10 @@ class Foo {
class Foo
{
const X = 'Humbug\\Symfony\\Component\\Yaml\\Yaml';
const X = 'Humbug\\Symfony\\Component\\Yaml\\Yaml';
const X = 'Humbug\\Symfony\\Component\\Yaml\\Yaml';
const X = 'Humbug\\Symfony\\Component\\Yaml\\Yaml';
const X = 'Humbug\\Symfony\\Component\\Yaml\\Ya_ml';
const X = 'Humbug\\Symfony\\Component\\Yaml\\Ya_ml';
const X = 'Humbug\\Symfony\\Component\\Yaml\\Ya_ml';
const X = 'Humbug\\Symfony\\Component\\Yaml\\Ya_ml';
const X = 'HelloWorld';
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpParser/NodeVisitor/StringScalarPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function enterNode(Node $node): Node
private function shouldPrefixScalar(Node $node): bool
{
if (false === ($node instanceof String_ && AppendParentNode::hasParent($node) && is_string($node->value))
|| 1 !== preg_match('/^\\\\*(?:\p{L}+\\\\+)++\p{L}+$/u', $node->value)
|| 1 !== preg_match('/^\\\\*(?:[\p{L}_]+\\\\+)++[\p{L}_]+$/u', $node->value)
) {
return false;
}
Expand Down

0 comments on commit 83b9abb

Please sign in to comment.