Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/graphql/parser/GraphqlAntlrToLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ private Value getValue(GraphqlParser.ValueContext ctx) {
throw new ShouldNotHappenException();
}

private String parseString(String string) {
static String parseString(String string) {
StringWriter writer = new StringWriter(string.length() - 2);
int end = string.length() - 1;
for (int i = 1; i < end; i++) {
Expand Down Expand Up @@ -778,7 +778,8 @@ private String parseString(String string) {
writer.write('\t');
continue;
case 'u':
int codepoint = Integer.parseInt(string.substring(i + 1, i + 5), 16);
String hexStr = string.substring(i + 1, i + 5);
int codepoint = Integer.parseInt(hexStr, 16);
i += 4;
writer.write(codepoint);
continue;
Expand Down
62 changes: 62 additions & 0 deletions src/test/groovy/graphql/parser/GraphqlAntlrToLanguageTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package graphql.parser

import spock.lang.Specification

class GraphqlAntlrToLanguageTest extends Specification {

def "parsing quoted string should work"() {
given:
def input = '''"simple quoted"'''

when:
String parsed = GraphqlAntlrToLanguage.parseString(input)

then:
parsed == "simple quoted"
}

def "parsing escaped json should work"() {
given:
def input = '''"{\"name\": \"graphql\", \"year\": 2015}"'''

when:
String parsed = GraphqlAntlrToLanguage.parseString(input)

then:
parsed == '''{\"name\": \"graphql\", \"year\": 2015}'''
}

def "parsing quoted quote should work"() {
given:
def input = '''"""'''

when:
String parsed = GraphqlAntlrToLanguage.parseString(input)

then:
parsed == '''"'''
}

def "parsing emoji should work"() {
// needs surrogate pairs for this emoji
given:
def input = '''"\\ud83c\\udf7a"'''

when:
String parsed = GraphqlAntlrToLanguage.parseString(input)

then:
parsed == '''🍺''' // contains the beer icon U+1F37A : http://www.charbase.com/1f37a-unicode-beer-mug
}

def "parsing simple unicode should work"() {
given:
def input = '''"\\u56fe"'''

when:
String parsed = GraphqlAntlrToLanguage.parseString(input)

then:
parsed == '''图'''
}
}