Skip to content

Commit 009f218

Browse files
committed
fix: patched EnumTransformer so it properly handles single quotes and is easier to extend for any other broken characters
1 parent 95f3b55 commit 009f218

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Transformers/EnumTransformer.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ protected function toEnumValue(ReflectionEnumBackedCase $case): string
7373
{
7474
$value = $case->getBackingValue();
7575

76-
return is_string($value) ? "'" . str_replace('\\', '\\\\', $value) . "'" : "{$value}";
76+
$newValue = "";
77+
78+
if (!is_string($value)) {
79+
return "{$value}";
80+
}
81+
82+
for ($i = 0; $i < strlen($value); $i++) {
83+
$char = $value[$i];
84+
85+
match ($char) {
86+
'\\' => $newValue .= '\\\\',
87+
'\'' => $newValue .= '\\\'',
88+
default => $newValue .= $char,
89+
};
90+
}
91+
92+
return "'" . $newValue . "'";
7793
}
7894
}

0 commit comments

Comments
 (0)