Skip to content

Commit 6339ca2

Browse files
committed
Strings, Validator: throw exception on invalid regexp patterns / malformed input
1 parent 27277a6 commit 6339ca2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Utils/Strings.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ public static function normalize(string $s): string
111111
$s = self::normalizeNewLines($s);
112112

113113
// remove control characters; leave \t + \n
114-
$s = preg_replace('#[\x00-\x08\x0B-\x1F\x7F-\x9F]+#u', '', $s);
114+
$s = self::pcre('preg_replace', ['#[\x00-\x08\x0B-\x1F\x7F-\x9F]+#u', '', $s]);
115115

116116
// right trim
117-
$s = preg_replace('#[\t ]+$#m', '', $s);
117+
$s = self::pcre('preg_replace', ['#[\t ]+$#m', '', $s]);
118118

119119
// leading and trailing blank lines
120120
$s = trim($s, "\n");
@@ -163,7 +163,7 @@ public static function toAscii(string $s): string
163163
. "\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe"
164164
. "\x96\xa0\x8b\x97\x9b\xa6\xad\xb7",
165165
'ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt- <->|-.');
166-
$s = preg_replace('#[^\x00-\x7F]++#', '', $s);
166+
$s = self::pcre('preg_replace', ['#[^\x00-\x7F]++#', '', $s]);
167167
} else {
168168
$s = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
169169
}
@@ -181,7 +181,7 @@ public static function webalize(string $s, string $charlist = null, bool $lower
181181
if ($lower) {
182182
$s = strtolower($s);
183183
}
184-
$s = preg_replace('#[^a-z0-9' . ($charlist !== null ? preg_quote($charlist, '#') : '') . ']+#i', '-', $s);
184+
$s = self::pcre('preg_replace', ['#[^a-z0-9' . ($charlist !== null ? preg_quote($charlist, '#') : '') . ']+#i', '-', $s]);
185185
$s = trim($s, '-');
186186
return $s;
187187
}

src/Utils/Validators.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static function is($value, string $expected): bool
144144
continue;
145145
}
146146
} elseif ($type === 'pattern') {
147-
if (preg_match('|^' . ($item[1] ?? '') . '$|D', $value)) {
147+
if (Strings::match($value, '|^' . ($item[1] ?? '') . '$|D')) {
148148
return true;
149149
}
150150
continue;

0 commit comments

Comments
 (0)