Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix string handling and use Regex.Unescape to convert escaped characters #76

Merged
merged 2 commits into from
Sep 8, 2023

Conversation

ricardoboss
Copy link
Owner

@ricardoboss ricardoboss commented Sep 8, 2023

Fixes #75.

The root cause of the issue was that only a special case for escapement was handled.
When the tokenizer encounters a " character, it enters a "string tokenizing mode" until it reads an unescaped " again.

If the tokenizer reads a \ when in "string tokenizing mode", it ignores the \ and enters an "escaped character mode" and appends the next character verbatim to the current token builder.

This worked fine if only the " is escaped. If any other character is escaped, the tokenizer only leaves the "escaped character mode" when it read a ".

The fix was a more general approach and an overhaul for the "escaped character mode".
It is now guaranteed to reset to the "string tokenizing mode" after an escaped character.

The escaped characters are now "unescaped" using Regex.Unescape, which takes care of individual escapes (like \n or \t) and hex escapes (\xa0).

@ricardoboss ricardoboss merged commit 7defe8d into main Sep 8, 2023
10 checks passed
@ricardoboss ricardoboss deleted the issues/75-support-character-escapes branch September 8, 2023 19:46
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.

Escaped characters are not tokenized correctly
1 participant