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

Support for escaped quotes #23

Closed
wants to merge 8 commits into from

Conversation

dmfxyz
Copy link
Contributor

@dmfxyz dmfxyz commented May 22, 2022

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:

`{key "val\""}`

is re-escaped to

`{key "val\\""}`

within the ebnf module itself.

So to address this I implemented

  • introduce unsafe type (only supports escaped quotes for now)
  • Only allowing unsafe to exist within quote
  • parsing quote child by child, and replacing the re-escaped characters only if the child is of type unsafe

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.

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(/\\/, "")
Copy link
Contributor Author

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.

@dmfxyz dmfxyz force-pushed the escape-sequences branch from 509dab9 to e5350ca Compare May 22, 2022 15:43
@nmushegian
Copy link
Owner

This is a good find. Thank you, please file an issue in their repo and point here

@dmfxyz
Copy link
Contributor Author

dmfxyz commented May 22, 2022

@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`)
Copy link
Owner

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

@nmushegian
Copy link
Owner

This is too many changes in one PR

@nmushegian nmushegian closed this May 22, 2022
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.

2 participants