Skip to content

Commit 85d52b0

Browse files
committed
ISSUES-88: add check value of position in while cycle after increment
1 parent 78ce14c commit 85d52b0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ Pattern scanRegex() {
139139
throw new JException("S0301", position);
140140
}
141141
position++;
142-
currentChar = path.charAt(position);
142+
if (position < length) {
143+
currentChar = path.charAt(position);
144+
} else {
145+
currentChar = 0;
146+
}
143147
// flags
144148
start = position;
145149
while (currentChar == 'i' || currentChar == 'm') {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.dashjoin.jsonata;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
public class RegexTest {
7+
@Test
8+
public void testRegex() {
9+
var expression = Jsonata.jsonata("/^test.*$/");
10+
Object evaluate = expression.evaluate(null);
11+
String expected = "^test.*$";
12+
Assertions.assertEquals(expected, evaluate.toString());
13+
}
14+
15+
@Test
16+
public void testEvalRegex() {
17+
var expression = Jsonata.jsonata("$eval('/^test.*$/')");
18+
Object evaluate = expression.evaluate(null);
19+
String expected = "^test.*$";
20+
Assertions.assertEquals(expected, evaluate.toString());
21+
}
22+
}

0 commit comments

Comments
 (0)