Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scoping of namespaces which have a dash in their namespace for string literals #211

Merged
merged 1 commit into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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