Skip to content

Commit 46daa78

Browse files
committed
Fix regex evaluation
Fixes #13
1 parent 3baa483 commit 46daa78

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/jsonata/tokenizer.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ def scan_regex(self) -> re.Pattern:
138138
start = self.position
139139
while current_char == 'i' or current_char == 'm':
140140
self.position += 1
141-
current_char = self.path[self.position]
141+
if self.position < self.length:
142+
current_char = self.path[self.position]
143+
else:
144+
current_char = None
142145
flags = self.path[start:self.position] + 'g'
143146

144147
# Convert flags to Java Pattern flags

tests/string_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def test_replace(self):
3838
assert jsonata.Jsonata("$replace('h.ello', '.', '')").evaluate(None) == "hello"
3939
assert jsonata.Jsonata("$replace('h.e.l.l.o', '.', '',2)").evaluate(None) == "hel.l.o"
4040

41+
def test_regex(self):
42+
assert (jsonata.Jsonata("($matcher := $eval('/^' & 'foo' & '/i'); $.$spread()[$.$keys() ~> $matcher])")
43+
.evaluate({"foo": 1, "bar": 2}) == {"foo": 1})
44+
4145
#
4246
# Additional $split tests
4347
#

0 commit comments

Comments
 (0)