File tree Expand file tree Collapse file tree 2 files changed +65
-2
lines changed
test/groovy/graphql/parser Expand file tree Collapse file tree 2 files changed +65
-2
lines changed Original file line number Diff line number Diff line change @@ -741,7 +741,7 @@ private Value getValue(GraphqlParser.ValueContext ctx) {
741741 throw new ShouldNotHappenException ();
742742 }
743743
744- private String parseString (String string ) {
744+ static String parseString (String string ) {
745745 StringWriter writer = new StringWriter (string .length () - 2 );
746746 int end = string .length () - 1 ;
747747 for (int i = 1 ; i < end ; i ++) {
@@ -778,7 +778,8 @@ private String parseString(String string) {
778778 writer .write ('\t' );
779779 continue ;
780780 case 'u' :
781- int codepoint = Integer .parseInt (string .substring (i + 1 , i + 5 ), 16 );
781+ String hexStr = string .substring (i + 1 , i + 5 );
782+ int codepoint = Integer .parseInt (hexStr , 16 );
782783 i += 4 ;
783784 writer .write (codepoint );
784785 continue ;
Original file line number Diff line number Diff line change 1+ package graphql.parser
2+
3+ import spock.lang.Specification
4+
5+ class GraphqlAntlrToLanguageTest extends Specification {
6+
7+ def " parsing quoted string should work" () {
8+ given :
9+ def input = ''' "simple quoted"'''
10+
11+ when :
12+ String parsed = GraphqlAntlrToLanguage . parseString(input)
13+
14+ then :
15+ parsed == " simple quoted"
16+ }
17+
18+ def " parsing escaped json should work" () {
19+ given :
20+ def input = ''' "{\" name\" : \" graphql\" , \" year\" : 2015}"'''
21+
22+ when :
23+ String parsed = GraphqlAntlrToLanguage . parseString(input)
24+
25+ then :
26+ parsed == ''' {\" name\" : \" graphql\" , \" year\" : 2015}'''
27+ }
28+
29+ def " parsing quoted quote should work" () {
30+ given :
31+ def input = ''' """'''
32+
33+ when :
34+ String parsed = GraphqlAntlrToLanguage . parseString(input)
35+
36+ then :
37+ parsed == ''' "'''
38+ }
39+
40+ def " parsing emoji should work" () {
41+ // needs surrogate pairs for this emoji
42+ given :
43+ def input = ''' "\\ ud83c\\ udf7a"'''
44+
45+ when :
46+ String parsed = GraphqlAntlrToLanguage . parseString(input)
47+
48+ then :
49+ parsed == ''' 🍺''' // contains the beer icon U+1F37A : http://www.charbase.com/1f37a-unicode-beer-mug
50+ }
51+
52+ def " parsing simple unicode should work" () {
53+ given :
54+ def input = ''' "\\ u56fe"'''
55+
56+ when :
57+ String parsed = GraphqlAntlrToLanguage . parseString(input)
58+
59+ then :
60+ parsed == ''' 图'''
61+ }
62+ }
You can’t perform that action at this time.
0 commit comments