Skip to content

Commit 78d2409

Browse files
authored
Merge pull request #60 from rayokota/fix-regexp
Fix regexp which ends in /i or /m the code is: while (currentChar == 'i') position++ path.charAt(position) when the regex ends with /i, position points "beyond" the string in JS, we chatAt simply returns "" in Java, we get an index out of bounds
2 parents 8ebe8d2 + 3dfcc17 commit 78d2409

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/main/java/com/dashjoin/jsonata/Tokenizer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ Pattern scanRegex() {
144144
start = position;
145145
while (currentChar == 'i' || currentChar == 'm') {
146146
position++;
147-
currentChar = path.charAt(position);
147+
if (position < length) {
148+
currentChar = path.charAt(position);
149+
} else {
150+
currentChar = 0;
151+
}
148152
}
149153
flags = path.substring(start, position) + 'g';
150154

src/test/java/com/dashjoin/jsonata/StringTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ public void evalTest() {
127127
+ " $eval('$data.Wert1')\n"
128128
+ ")").evaluate(null));
129129
}
130+
131+
@Test
132+
public void regexTest() {
133+
Assertions.assertEquals(Map.of("foo", 1), jsonata(
134+
"($matcher := $eval('/^' & 'foo' & '/i'); $.$spread()[$.$keys() ~> $matcher])")
135+
.evaluate(Map.of("foo", 1, "bar", 2)));
136+
}
130137

131138
@Disabled
132139
@Test

0 commit comments

Comments
 (0)