Skip to content

Commit 6490fc8

Browse files
committed
Minor cleanup
1 parent e378a93 commit 6490fc8

2 files changed

Lines changed: 20 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
@@ -142,7 +142,11 @@ Pattern scanRegex() {
142142
start = position;
143143
while (currentChar == 'i' || currentChar == 'm') {
144144
position++;
145-
currentChar = path.charAt(position);
145+
if (position < length) {
146+
currentChar = path.charAt(position);
147+
} else {
148+
currentChar = 0;
149+
}
146150
}
147151
flags = path.substring(start, position) + 'g';
148152

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.dashjoin.jsonata;
22

33
import static com.dashjoin.jsonata.Jsonata.jsonata;
4+
45
import java.util.Arrays;
56
import java.util.Map;
67
import org.junit.jupiter.api.Assertions;
@@ -127,4 +128,18 @@ public void evalTest() {
127128
+ " $eval('$data.Wert1')\n"
128129
+ ")").evaluate(null));
129130
}
131+
132+
@Test
133+
public void regexTest() {
134+
Assertions.assertEquals(Map.of("foo", 1), jsonata(
135+
"($matcher := $eval('/^' & 'foo' & '/i'); $.$spread()[$.$keys() ~> $matcher])")
136+
.evaluate(Map.of("foo", 1, "bar", 2)));
137+
}
138+
139+
@Disabled
140+
@Test
141+
public void replaceTest() {
142+
Assertions.assertEquals("http://example.org/test",
143+
jsonata("$replace($, /{par}/, '')").evaluate("http://example.org/test{par}"));
144+
}
130145
}

0 commit comments

Comments
 (0)