Skip to content

Commit

Permalink
Future-proof collisions with extended Symfony classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthecow committed Oct 13, 2023
1 parent 14462ee commit d56ea5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Input/ShellInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
class ShellInput extends StringInput
{
public const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)';

private $hasCodeArgument = false;

/**
Expand Down Expand Up @@ -98,7 +100,7 @@ private function tokenize(string $input): array
\stripcslashes(\substr($match[0], 1, \strlen($match[0]) - 2)),
\stripcslashes(\substr($input, $cursor)),
];
} elseif (\preg_match('/'.StringInput::REGEX_STRING.'/A', $input, $match, 0, $cursor)) {
} elseif (\preg_match('/'.self::REGEX_STRING.'/A', $input, $match, 0, $cursor)) {
$tokens[] = [
\stripcslashes($match[1]),
\stripcslashes(\substr($input, $cursor)),
Expand Down
13 changes: 6 additions & 7 deletions src/VarDumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class Dumper extends CliDumper
private $formatter;
private $forceArrayIndexes;

protected static $onlyControlCharsRx = '/^[\x00-\x1F\x7F]+$/';
protected static $controlCharsRx = '/([\x00-\x1F\x7F]+)/';
protected static $controlCharsMap = [
const ONLY_CONTROL_CHARS = '/^[\x00-\x1F\x7F]+$/';
const CONTROL_CHARS = '/([\x00-\x1F\x7F]+)/';
const CONTROL_CHARS_MAP = [
"\0" => '\0',
"\t" => '\t',
"\n" => '\n',
Expand Down Expand Up @@ -71,16 +71,15 @@ protected function style($style, $value, $attr = []): string
}

$styled = '';
$map = self::$controlCharsMap;
$cchr = $this->styles['cchr'];

$chunks = \preg_split(self::$controlCharsRx, $value, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE);
$chunks = \preg_split(self::CONTROL_CHARS, $value, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE);
foreach ($chunks as $chunk) {
if (\preg_match(self::$onlyControlCharsRx, $chunk)) {
if (\preg_match(self::ONLY_CONTROL_CHARS, $chunk)) {
$chars = '';
$i = 0;
do {
$chars .= isset($map[$chunk[$i]]) ? $map[$chunk[$i]] : \sprintf('\x%02X', \ord($chunk[$i]));
$chars .= isset(self::CONTROL_CHARS_MAP[$chunk[$i]]) ? self::CONTROL_CHARS_MAP[$chunk[$i]] : \sprintf('\x%02X', \ord($chunk[$i]));
} while (isset($chunk[++$i]));

$chars = $this->formatter->escape($chars);
Expand Down

0 comments on commit d56ea5b

Please sign in to comment.