Skip to content

Commit

Permalink
Skip hexa chars in EncapsedStringsToSprintfRector (#6719)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba authored Feb 5, 2025
1 parent 95a145f commit 78382d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$key = '...';

$value = "first:\x01second\x01{$key}";
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,21 @@ public function refactor(Node $node): ?Node

private function shouldSkip(InterpolatedString $interpolatedString): bool
{
return $interpolatedString->hasAttribute(AttributeKey::DOC_LABEL);
if ($interpolatedString->hasAttribute(AttributeKey::DOC_LABEL)) {
return true;
}

foreach ($interpolatedString->parts as $part) {
if (! $part instanceof InterpolatedStringPart) {
continue;
}

if ($this->containsASCIIChar($part->value)) {
return true;
}
}

return false;
}

private function collectEncapsedStringPart(InterpolatedStringPart $interpolatedStringPart): void
Expand Down Expand Up @@ -250,4 +264,9 @@ private function createString(string $value): String_
'kind' => $kind,
]);
}

private function containsASCIIChar(string $content): bool
{
return (bool) Strings::match($content, '#[\x00-\x08\x0B\x0C\x0E-\x1F]#');
}
}

0 comments on commit 78382d2

Please sign in to comment.