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
7 changes: 6 additions & 1 deletion src/main/java/graphql/parser/GraphqlAntlrToLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,12 @@ protected Value createValue(GraphqlParser.ValueWithVariableContext ctx) {
addCommonData(intValue, ctx);
return captureRuleContext(intValue.build(), ctx);
} else if (ctx.FloatValue() != null) {
FloatValue.Builder floatValue = FloatValue.newFloatValue().value(new BigDecimal(ctx.FloatValue().getText()));
FloatValue.Builder floatValue;
try {
floatValue = FloatValue.newFloatValue().value(new BigDecimal(ctx.FloatValue().getText()));
} catch (NumberFormatException e) {
throw new InvalidSyntaxException("Invalid floating point value", null, ctx.FloatValue().getText(), null, e);
}
addCommonData(floatValue, ctx);
return captureRuleContext(floatValue.build(), ctx);
} else if (ctx.BooleanValue() != null) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/graphql/parser/UnicodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public static int parseAndWriteUnicode(I18n i18n, StringWriter writer, String st
int continueIndex = isBracedEscape(string, i) ? endIndexExclusive : endIndexExclusive - 1;

String hexStr = string.substring(startIndex, endIndexExclusive);
int codePoint = Integer.parseInt(hexStr, 16);
int codePoint;
try {
codePoint = Integer.parseInt(hexStr, 16);
} catch (NumberFormatException e) {
throw new InvalidUnicodeSyntaxException(i18n, "InvalidUnicode.invalidHexString", sourceLocation, offendingToken(string, i, continueIndex));
}

if (isTrailingSurrogateValue(codePoint)) {
throw new InvalidUnicodeSyntaxException(i18n, "InvalidUnicode.trailingLeadingSurrogate", sourceLocation, offendingToken(string, i, continueIndex));
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/graphql/schema/idl/SchemaParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package graphql.schema.idl;

import org.testng.annotations.Test;
import graphql.GraphQLException;

public class SchemaParserTest {

@Test
public void testNumberFormatException() {
String[] malformedStrings = {
"{B(t:66E3333333320,t:#\n66666666660)},622»» »»»6666662}}6666660t:z6666"
};

for (String malformed : malformedStrings) {
try {
SchemaParser parser = new SchemaParser();
parser.parse(malformed);
} catch (GraphQLException e) {
// Known exception
}
}
}
}