jmespath-ts icon indicating copy to clipboard operation
jmespath-ts copied to clipboard

Escaping Multiple Single Quotes in Raw String Literal

Open zaydu98 opened this issue 1 year ago • 2 comments

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.

zaydu98 avatar Oct 02 '24 15:10 zaydu98

@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 avatar Oct 27 '24 07:10 springcomp

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

springcomp avatar Oct 27 '24 08:10 springcomp