Skip to content

Conversation

theawless
Copy link

Fix unicode backslash escaped double quote in string and char literals

Closes #209

As described in JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.2, the translation for unicode escapes happens before parsing. Hence this is allowed:

Original: '\u005c''
After Unicode escape processing: '\''
Final interpretation: a char literal containing a single quote character

To handle this behaviour I've updated the existing rules such that wherever \\ was accepted \u005c is also accepted.

Allow multiple u chars in unicode escapes within string literals

Closes #207

I feel it's weird but it is mentioned in the JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.2:~:text=If%20an%20eligible%20%5C%20is%20followed%20by%20u%2C%20or%20more%20than%20one%20u%2C%20and%20the%20last%20u%20is%20not%20followed%20by%20four%20hexadecimal%20digits%2C%20then%20a%20compile%2Dtime%20error%20occurs - there can be multiple u after \u as long as the 4 hex digits come at the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parsing error for unicode escape in char/string literals Parsing error for unicode in string literals
1 participant