laracasts / PHP-Vars-To-Js-Transformer

Transform PHP data to JavaScript.
https://packagist.org/packages/laracasts/utilities
MIT License
2.21k stars 219 forks source link

Fix newline in input string to generate invalid javascript #88

Closed martindilling closed 7 years ago

martindilling commented 8 years ago

When the input string contains newline characters the generated javascript is invalid as strings in javascript can't span multiple lines. (related: #52)

Here I'm just escaping newline characters "\n" so the generated javascript contains the actual "\" and "n" characters, then javascript will interpret that as the newline character... this is really strange to try and explain xD