-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support for escaped quotes #23
Conversation
jams.js
Outdated
if (child.type == "unsafe") { | ||
// EBNF module re-escapes strings, so "\" becomes "\\" | ||
// iff child is of unsafe type do we re-do the unescape | ||
let unescaped = child.text.replace(/\\/, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we reverted this before, but now we only do it for unsafe children.
This is a good find. Thank you, please file an issue in their repo and point here |
@nmushegian see here for more issue and example: lys-lang/node-ebnf#41 |
o = jams(`{key "val"}`) | ||
t.equal(o.key, "val") | ||
o = jams(String.raw`{"\"key" "\"val"}`) // Need raw so js doesn't escape \ | ||
t.equal(o[`"key`], `"val`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test shouldn’t even pass based on latest requirement
The point is to separate out bareword part and at least get that done first
Also global replace like this is probably never the right solution
This is too many changes in one PR |
PR includes changes from #22, that one can be merged first to see true diff.
There is a problem with the ebnf module we use -- it auto escapes strings somewhere in its implementation. For example the string:
is re-escaped to
within the ebnf module itself.
So to address this I implemented
unsafe
type (only supports escaped quotes for now)unsafe
to exist withinquote
quote
child by child, and replacing the re-escaped characters only if the child is of typeunsafe
We could redefine the grammar to expect the double
\\
, but this would be an inaccurate grammar tailored to our specific parser.Added new file based tests that are all passing. If we have a list of other characters that should be escaped, I can add them too.