Skip to content

Commit 0ddae4b

Browse files
authored
Fix special characters in parsing serial numbers
1 parent 74ca7e6 commit 0ddae4b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/SerialNumberGenerator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public function parse(string $serialNumber): array
163163

164164
protected function formatToRegex(): string
165165
{
166+
$format = preg_replace('/([^\w\s])/i', '\\\\$1', $this->format);
167+
166168
$value = preg_replace_callback_array(
167169
[
168170
'/P+/' => fn ($matches) => ($matches[0] && $length = mb_strlen($matches[0])) ? "(?<prefix>[a-zA-Z]{{$length}})" : '',
@@ -171,7 +173,7 @@ protected function formatToRegex(): string
171173
'/Y+/' => fn ($matches) => ($matches[0] && $length = mb_strlen($matches[0])) ? "(?<year>\d{{$length}})" : '',
172174
'/C+/' => fn ($matches) => ($matches[0] && $length = mb_strlen($matches[0])) ? "(?<count>\d{{$length}})" : '',
173175
],
174-
$this->format
176+
$format
175177
);
176178

177179
return is_string($value) ? $value : '';

0 commit comments

Comments
 (0)