Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/main/java/graphql/parser/UnicodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ public static int parseAndWriteUnicode(I18n i18n, StringWriter writer, String st
i = continueIndex + 2;
int trailingStartIndex = isBracedEscape(string, i) ? i + 2 : i + 1;
int trailingEndIndexExclusive = getEndIndexExclusive(i18n, string, i, sourceLocation);
int trailingCodePoint = Integer.parseInt(string, trailingStartIndex, trailingEndIndexExclusive, 16);
continueIndex = isBracedEscape(string, i) ? trailingEndIndexExclusive : trailingEndIndexExclusive - 1;

int trailingCodePoint;
try {
trailingCodePoint = Integer.parseInt(string, trailingStartIndex, trailingEndIndexExclusive, 16);
} catch (NumberFormatException e) {
throw new InvalidUnicodeSyntaxException(i18n, "InvalidUnicode.invalidHexString", sourceLocation, offendingToken(string, i, continueIndex));
}

if (isTrailingSurrogateValue(trailingCodePoint)) {
writeCodePoint(writer, codePoint);
writeCodePoint(writer, trailingCodePoint);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/i18n/Parsing.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ InvalidUnicode.trailingLeadingSurrogate=Invalid unicode encountered. Trailing su
InvalidUnicode.leadingTrailingSurrogate=Invalid unicode encountered. Leading surrogate must be followed by a trailing surrogate. Offending token ''{0}'' at line {1} column {2}
InvalidUnicode.invalidCodePoint=Invalid unicode encountered. Not a valid code point. Offending token ''{0}'' at line {1} column {2}
InvalidUnicode.incorrectEscape=Invalid unicode encountered. Incorrectly formatted escape sequence. Offending token ''{0}'' at line {1} column {2}
InvalidUnicode.invalidHexString=Invalid unicode encountered. Not a valid hex digits string. Offending token ''{0}'' at line {1} column {2}
1 change: 1 addition & 0 deletions src/main/resources/i18n/Parsing_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ InvalidUnicode.trailingLeadingSurrogate=Ungültiger Unicode gefunden. Trailing s
InvalidUnicode.leadingTrailingSurrogate=Ungültiger Unicode gefunden. Auf ein leading surrogate muss ein trailing surrogate folgen. Ungültiges Token ''{0}'' in Zeile {1} Spalte {2}
InvalidUnicode.invalidCodePoint=Ungültiger Unicode gefunden. Kein gültiger code point. Ungültiges Token ''{0}'' in Zeile {1} Spalte {2}
InvalidUnicode.incorrectEscape=Ungültiger Unicode gefunden. Falsch formatierte Escape-Sequenz. Ungültiges Token ''{0}'' in Zeile {1} Spalte {2}
InvalidUnicode.invalidHexString=Ungültiger Unicode gefunden. Keine gültige Hexadezimalzeichenfolge. Ungültiges Token ''{0}'' in Zeile {1} Spalte {2}
1 change: 1 addition & 0 deletions src/main/resources/i18n/Parsing_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ InvalidUnicode.trailingLeadingSurrogate=Ongeldige Unicode tegengekomen. Trailing
InvalidUnicode.leadingTrailingSurrogate=Ongeldige Unicode tegengekomen. Leading surrogate moet voorafgaan aan een trailing surrogate. Ongeldige token ''{0}'' op lijn {1} kolom {2}
InvalidUnicode.invalidCodePoint=Ongeldige Unicode tegengekomen. Ongeldig codepunt. Ongeldige token ''{0}'' op lijn {1} kolom {2}
InvalidUnicode.incorrectEscape=Ongeldige Unicode tegengekomen. Ongeldige geformatteerde escape-sequentie. Ongeldige token ''{0}'' op lijn {1} kolom {2}}
InvalidUnicode.invalidHexString=Ongeldige Unicode tegengekomen. Geen geldige hexadecimale tekenreeks. Ongeldige token ''{0}'' op lijn {1} kolom {2}
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,28 @@ class StringValueParsingUnicodeTest extends Specification {
InvalidSyntaxException e = thrown(InvalidSyntaxException)
e.message == "Invalid unicode encountered. Not a valid code point. Offending token '\\u{fffffff}' at line -1 column -1"
}

def "invalid unicode code point - braced hex value overflows int"() {
given:
def input = '''"\\u{fffffffff}"'''

when:
StringValueParsing.parseSingleQuotedString(i18n, input,sourceLocation)

then:
InvalidSyntaxException e = thrown(InvalidSyntaxException)
e.message == "Invalid unicode encountered. Not a valid hex digits string. Offending token '\\u{fffffffff}' at line -1 column -1"
}

def "invalid surrogate pair - trailing braced hex value overflows int"() {
given:
def input = '''"\\uD83D\\u{fffffffff}"'''

when:
StringValueParsing.parseSingleQuotedString(i18n, input,sourceLocation)

then:
InvalidSyntaxException e = thrown(InvalidSyntaxException)
e.message == "Invalid unicode encountered. Not a valid hex digits string. Offending token '\\u{fffffffff}' at line -1 column -1"
}
}