trivago / melody

Melody is a library for building JavaScript web applications.
https://melody.js.org
Apache License 2.0
215 stars 39 forks source link

Bugfix: Preserve backslashes in string literals #149

Closed twbartel closed 4 years ago

twbartel commented 4 years ago

So far, the Lexer dropped all backslashes from string literals. Removing this behaviour caused only one single test case to fail, where a quote character was escaped:

var lexer = new Lexer(new CharStream("hello {{ 'test\\'n this' }}world"));

While here, a quote character is escaped, the intended behaviour should not be to simply remove all backslashes.

This PR limits backslash removal to backslashes before quotes. Moreover, it introduces an option preserveSourceLiterally which prevents backslash removal entirely and supersedes the decodeEntities option.