Skip to content

Commit 739f051

Browse files
committed
Added special case: empty search string for find_first() func.
1 parent 93c54fe commit 739f051

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

jmespath/functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ def _func_keys(self, arg):
314314
{'type': 'number', 'optional': True},
315315
{'type': 'number', 'optional': True})
316316
def _func_find_first(self, text, search, start = 0, end = -1):
317+
if len(search) == 0:
318+
return None
317319
if end == -1:
318320
end = len(text)
319321
pos = text.find(search, start, end)

tests/compliance/string_functions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
{ "expression": "find_first(string, 'string', `9`)", "result": null },
3333
{ "expression": "find_first(string, 's')", "result": 0 },
3434
{ "expression": "find_first(string, 's', `1`)", "result": 8 },
35+
{ "expression": "find_first(string, '')", "result": null },
3536

3637
{ "expression": "find_last(string, 'string')", "result": 8 },
3738
{ "expression": "find_last(string, 'string', `8`)", "result": 8 },

0 commit comments

Comments
 (0)