[Serializer] Fix excessive backtracking in name converters

This commit is contained in:
Younes ENNAJI
2026-01-12 21:15:26 +01:00
committed by Nicolas Grekas
parent 317b217c21
commit 7d2a5e69c8
2 changed files with 2 additions and 6 deletions

View File

@@ -63,7 +63,7 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
throw new UnexpectedPropertyException($propertyName);
}
$camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', static fn ($match) => ('.' === $match[1] ? '_' : '').strtoupper($match[2]), $propertyName);
$camelCasedName = preg_replace_callback('/(^|_|\.)++(.)/', static fn ($match) => ('.' === $match[1] ? '_' : '').strtoupper($match[2]), $propertyName);
if ($this->lowerCamelCase) {
$camelCasedName = lcfirst($camelCasedName);

View File

@@ -45,11 +45,7 @@ final class SnakeCaseToCamelCaseNameConverter implements NameConverterInterface
return $propertyName;
}
$camelCasedName = preg_replace_callback(
'/(^|_|\.)+(.)/',
static fn ($match) => ('.' === $match[1] ? '_' : '').strtoupper($match[2]),
$propertyName
);
$camelCasedName = preg_replace_callback('/(^|_|\.)++(.)/', static fn ($match) => ('.' === $match[1] ? '_' : '').strtoupper($match[2]), $propertyName);
if ($this->lowerCamelCase) {
$camelCasedName = lcfirst($camelCasedName);