Skip to content

Commit 6996f9d

Browse files
committed
Merge branch 'issue-85' into develop
* issue-85: Process escaped single quotes
2 parents f90040c + d76c617 commit 6996f9d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

jmespath/lexer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ def _consume_until(self, delimiter):
125125

126126
def _consume_literal(self):
127127
start = self._position
128-
lexeme = self._consume_until('`')
129-
lexeme = lexeme.replace('\\`', '`')
128+
lexeme = self._consume_until('`').replace('\\`', '`')
130129
try:
131130
# Assume it is valid JSON and attempt to parse.
132131
parsed_json = loads(lexeme)
@@ -160,7 +159,7 @@ def _consume_quoted_identifier(self):
160159

161160
def _consume_raw_string_literal(self):
162161
start = self._position
163-
lexeme = self._consume_until("'")
162+
lexeme = self._consume_until("'").replace("\\'", "'")
164163
token_len = self._position - start
165164
return {'type': 'literal', 'value': lexeme,
166165
'start': start, 'end': token_len}

tests/compliance/literal.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@
179179
"comment": "Do not interpret escaped unicode.",
180180
"expression": "'\\u03a6'",
181181
"result": "\\u03a6"
182+
},
183+
{
184+
"comment": "Can escape the single quote",
185+
"expression": "'foo\\'bar'",
186+
"result": "foo'bar"
182187
}
183188
]
184189
}

0 commit comments

Comments
 (0)