Skip to content

Commit 3580739

Browse files
committed
Remove redundant regex character escapes
1 parent ded5177 commit 3580739

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/Parser.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected static function getExpression(string $v, Context $context, int|string
115115
}
116116

117117
if (str_contains($v, ']')) {
118-
preg_match_all('/(\\[[^\\]]+\\]|[^\\[\\]\\.]+)/', $v, $matchedAll);
118+
preg_match_all('/(\[[^]]+]|[^\[\].]+)/', $v, $matchedAll);
119119
} else {
120120
preg_match_all('/([^.\\/]+)/', $v, $matchedAll);
121121
}
@@ -185,7 +185,7 @@ public static function getPartialName(array $vars, int $pos = 0): ?array
185185
return null;
186186
}
187187
assert(is_string($vars[$pos]));
188-
return [preg_replace('/^("(.+)")|(\\[(.+)\\])|(\\\\\'(.+)\\\\\')$/', '$2$4$6', $vars[$pos])];
188+
return [preg_replace('/^("(.+)")|(\\[(.+)])|(\\\\\'(.+)\\\\\')$/', '$2$4$6', $vars[$pos])];
189189
}
190190

191191
/**
@@ -243,7 +243,7 @@ protected static function advancedVariable(array $vars, Context $context, string
243243
continue;
244244
}
245245

246-
if (preg_match('/^((\\[([^\\]]+)\\])|([^=^\\["\']+))=(.+)$/s', $var, $m)) {
246+
if (preg_match('/^((\[([^]]+)])|([^=^\["\']+))=(.+)$/s', $var, $m)) {
247247
$idx = $m[3] ?: $m[4];
248248
$var = $m[5];
249249
// handle foo=(...)
@@ -261,11 +261,11 @@ protected static function advancedVariable(array $vars, Context $context, string
261261
// ]bar. Rule 3: middle ] not before .
262262
|| preg_match('/][^\\[.\\]]+\\./', $var)
263263
// .foo[ Rule 4: middle [ not after .
264-
|| preg_match('/\\.[^\\[.\\]]+\\[/', preg_replace('/^(..\\/)+/', '', preg_replace('/\\[[^\\]]+\\]/', '[XXX]', $var)))
264+
|| preg_match('/\\.[^\\[.\\]]+\\[/', preg_replace('/^(..\\/)+/', '', preg_replace('/\[[^]]+]/', '[XXX]', $var)))
265265
) {
266266
$context->error[] = "Wrong variable naming as '$var' in $token !";
267267
} else {
268-
$name = preg_replace('/(\\[.+?\\])/', '', $var);
268+
$name = preg_replace('/(\[.+?])/', '', $var);
269269
// Scan for invalid characters which not be protected by [ ]
270270
// now make ( and ) pass, later fix
271271
if (preg_match('/[!"#%\'*+,;<=>{|}~]/', $name)) {

0 commit comments

Comments
 (0)