Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jmespath.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@
}
this._current++;
var literal = stream.slice(start + 1, this._current - 1);
return literal.replace("\\'", "'");
return literal.replace(/\\'/g, "'");
},

_consumeNumber: function(stream) {
Expand Down
48 changes: 48 additions & 0 deletions test/compliance/literal.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,54 @@
"comment": "Can escape the single quote",
"expression": "'foo\\'bar'",
"result": "foo'bar"
},
{
"comment": "Unescape every single quote in a raw string",
"expression": "'foo\\'bar\\'baz'",
"result": "foo'bar'baz"
},
{
"comment": "Unescape consecutive single quotes",
"expression": "'\\'\\''",
"result": "''"
},
{
"comment": "Unescape quotes at both ends of the raw string",
"expression": "'\\'foo\\''",
"result": "'foo'"
},
{
"comment": "Preserve other raw escapes while unescaping all quotes",
"expression": "'\\nfoo\\'bar\\'\\u03a6'",
"result": "\\nfoo'bar'\\u03a6"
},
{
"comment": "Unescape all quotes in each raw string",
"expression": "['a\\'b\\'c', 'd\\'e\\'f']",
"result": [
"a'b'c",
"d'e'f"
]
}
]
},
{
"comment": "Filter with repeated escaped single quotes",
"given": [
{
"title": "O'Reilly's book"
},
{
"title": "Another book"
},
{
"title": "O'Reilly's book"
}
],
"cases": [
{
"expression": "length([?title == 'O\\'Reilly\\'s book'])",
"result": 2
}
]
}
Expand Down