Readable enum values should be escaped when generating javascript eums
Closed this issue · 2 comments
bendavies commented
Hi there,
If a readable enum value contains characters that should be escaped in javascript strings, they need to be escaped in the JsDumper
for example:
class Foo extends ReadableEnum {
static NICE = 'nice',
static get readables() {
return {
[Foo.NICE]: 'it\'s nice'
};
}
}
but at the moment it will be dumped as invalid javascript:
class Foo extends ReadableEnum {
static NICE = 'nice',
static get readables() {
return {
[Foo.NICE]: 'it's nice'
};
}
}
How would you like to fix this?
we can use
htmlspecialchars
?- something more complex like twig's js escaper?
- something else?
Thanks!
ogizanagi commented
Hi! Thank you for nice and clear bug report. 🙏🏻
I guess using json_encode
might be enough instead of
PhpEnums/src/JsDumper/JsDumper.php
Line 169 in 7d4cb3c
with hardcoded single quotes.
bendavies commented
thanks, i'll proceed on that basis