Skip to content

Commit 33c2297

Browse files
committed
Merge tag 'JEP-15' into feature/vnext-preview
2 parents af6ae13 + a89da7f commit 33c2297

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

jmespath/visitor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ def visit_index_expression(self, node, value):
261261
return result
262262

263263
def visit_slice(self, node, value):
264+
if isinstance(value, string_type):
265+
start = node['children'][0]
266+
end = node['children'][1]
267+
step = node['children'][2]
268+
return value[start:end:step]
269+
264270
if not isinstance(value, list):
265271
return None
266272
s = slice(*node['children'])
@@ -312,6 +318,17 @@ def visit_pipe(self, node, value):
312318

313319
def visit_projection(self, node, value):
314320
base = self.visit(node['children'][0], value)
321+
322+
allow_string = False
323+
first_child = node['children'][0]
324+
if first_child['type'] == 'index_expression':
325+
nested_children = first_child['children']
326+
if len(nested_children) > 1 and nested_children[1]['type'] == 'slice':
327+
allow_string = True
328+
329+
if isinstance(base, string_type) and allow_string:
330+
return base
331+
315332
if not isinstance(base, list):
316333
return None
317334
collected = []

tests/compliance/slice.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,12 @@
184184
"result": []
185185
}
186186
]
187+
}, {
188+
"given": null,
189+
"cases": [
190+
{
191+
"expression": "'e\u0301le\u0301ment'[::-1]",
192+
"result": "tnem\u0301el\u0301e"
193+
}
194+
]
187195
}]

0 commit comments

Comments
 (0)