File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
main/java/com/dashjoin/jsonata
test/java/com/dashjoin/jsonata Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -263,12 +263,12 @@ Token next(boolean prefix) {
263263 currentChar = path .charAt (position );
264264 if (currentChar == '\\' ) { // escape sequence
265265 position ++;
266- currentChar = path .charAt (position );
266+ if ( position < path . length ()) currentChar = path .charAt (position ); else throw new JException ( "S0103" , position , "" );
267267 if (escapes .get ("" +currentChar )!=null ) {
268268 qstr += escapes .get ("" +currentChar );
269269 } else if (currentChar == 'u' ) {
270270 // u should be followed by 4 hex digits
271- String octets = path .substring (position + 1 , (position + 1 ) + 4 );
271+ String octets = position + 5 < path .length () ? path . substring (position + 1 , (position + 1 ) + 4 ) : "" ;
272272 if (octets .matches ("^[0-9a-fA-F]+$" )) { // /^[0-9a-fA-F]+$/.test(octets)) {
273273 int codepoint = Integer .parseInt (octets , 16 );
274274 qstr += Character .toString ((char ) codepoint );
@@ -278,7 +278,7 @@ Token next(boolean prefix) {
278278 }
279279 } else {
280280 // illegal escape sequence
281- throw new JException ("S0301 " , position , currentChar );
281+ throw new JException ("S0103 " , position , currentChar );
282282
283283 }
284284 } else if (currentChar == quoteType ) {
Original file line number Diff line number Diff line change 1+ package com .dashjoin .jsonata ;
2+
3+ import static com .dashjoin .jsonata .Jsonata .jsonata ;
4+ import org .junit .jupiter .api .Assertions ;
5+ import org .junit .jupiter .api .Test ;
6+
7+ public class ParserTest {
8+
9+ @ Test
10+ public void testUnsupportedEscapeSequence () {
11+ Assertions .assertThrows (JException .class , ()->jsonata ("$substring('input', '\\ a" ));
12+ Assertions .assertThrows (JException .class , ()->jsonata ("$substring('input', '\\ " ));
13+ Assertions .assertEquals ("" , jsonata ("$substring('\\ \\ ', 1)" ).evaluate (null ));
14+
15+ Assertions .assertThrows (JException .class , ()->jsonata ("$substring('\\ u" ));
16+ Assertions .assertEquals ("" , jsonata ("$substring('\\ uDDDD', 1)" ).evaluate (null ));
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments