nanoporetech / jmespath-ts

Typescript translation of the jmespath.js package
Mozilla Public License 2.0
64 stars 7 forks source link

Escaping Multiple Single Quotes in Raw String Literal #42

Open zaydu98 opened 2 months ago

zaydu98 commented 2 months ago

Hey I noticed when trying to match a JMESPath expression that uses raw string literals with more than one escaped single quote, the matching fails. According to the proposal: https://jmespath.org/proposals/raw-string-literals.html : "This proposal states that single quotes in a raw string literal must be escaped with a backslash." And in the spec: raw-string-escape = escape ("'" / escape)

When trying to match an expression with only one escaped single quote, it succeeds. If I add more than one, it fails to match but still compiles. Example: JMESPath Expression: contains(['something\\''],a) This returns true if a equals something'. If I add an additional escaped single quote, matching fails. Example: JMESPath Expression: contains(['some\\'thing\\''],a) This should match if a equals some'thing' but does not.

springcomp commented 1 month ago

@zaydu98

I’m not sure what shell or programming language you use, but the correct expression should only contain a single backslash character to escape a quote.

search( contains(['wanna be starting something'], a) , {"a": "wanna be starting something"} ) → true search( contains(['wanna be starting somethin\''], a) , {"a": "wanna be starting somethin'"} ) → true search( contains(['wanna be startin\' somethin\''], a) , {"a": "wanna be startin' somethin'"} ) → true

springcomp commented 1 month ago

@zaydu98 you might want to use @jmespath-community/typescript.jmespath which is a fork of this library and already contains this fix.