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 5927f39 commit bbf109f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 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
22 changes: 18 additions & 4 deletions src/VarDumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ class Dumper extends CliDumper
private $formatter;
private $forceArrayIndexes;

const ONLY_CONTROL_CHARS = '/^[\x00-\x1F\x7F]+$/';
const CONTROL_CHARS = '/([\x00-\x1F\x7F]+)/';
const CONTROL_CHARS_MAP = [
"\0" => '\0',
"\t" => '\t',
"\n" => '\n',
"\v" => '\v',
"\f" => '\f',
"\r" => '\r',
"\033" => '\e',
];

/** @deprecated */
protected static $onlyControlCharsRx = '/^[\x00-\x1F\x7F]+$/';
/** @deprecated */
protected static $controlCharsRx = '/([\x00-\x1F\x7F]+)/';
/** @deprecated */
protected static $controlCharsMap = [
"\0" => '\0',
"\t" => '\t',
Expand Down Expand Up @@ -71,16 +86,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 bbf109f

Please sign in to comment.