Skip to content

Commit a78f62f

Browse files
authored
Merge pull request #4481 from nab-iha3/float-const-exponent-syntax-error
throw InvalidSyntaxException on out-of-range float exponent in const values
2 parents 27821ed + 6edcf07 commit a78f62f

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎src/main/java/graphql/parser/GraphqlAntlrToLanguage.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,12 @@ protected Value createValue(GraphqlParser.ValueContext ctx) {
744744
addCommonData(intValue, ctx);
745745
return captureRuleContext(intValue.build(), ctx);
746746
} else if (ctx.FloatValue() != null) {
747-
FloatValue.Builder floatValue = FloatValue.newFloatValue().value(new BigDecimal(ctx.FloatValue().getText()));
747+
FloatValue.Builder floatValue;
748+
try {
749+
floatValue = FloatValue.newFloatValue().value(new BigDecimal(ctx.FloatValue().getText()));
750+
} catch (NumberFormatException e) {
751+
throw new InvalidSyntaxException("Invalid floating point value", null, ctx.FloatValue().getText(), null, e);
752+
}
748753
addCommonData(floatValue, ctx);
749754
return captureRuleContext(floatValue.build(), ctx);
750755
} else if (ctx.BooleanValue() != null) {

‎src/test/groovy/graphql/parser/ParserTest.groovy‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,22 @@ triple3 : """edge cases \\""" "" " \\"" \\" edge cases"""
10091009
'1.2e3e' | _
10101010
}
10111011

1012+
@Unroll
1013+
def "float literal with out-of-range exponent #value is a syntax error"() {
1014+
when:
1015+
Parser.parse(input)
1016+
1017+
then:
1018+
def e = thrown(InvalidSyntaxException)
1019+
e.message.contains("Invalid floating point value")
1020+
1021+
where:
1022+
input | value
1023+
'query($x: Float = 1.0e9999999999) {foo}' | '1.0e9999999999 (variable default value)'
1024+
'query($x: Float = [1.0e9999999999]) {foo}' | '1.0e9999999999 (nested in list default)'
1025+
'{foo(arg: 1.0e9999999999)}' | '1.0e9999999999 (argument value)'
1026+
}
1027+
10121028
@Unroll
10131029
def 'parse ast field definition #valueLiteral'() {
10141030
expect:

0 commit comments

Comments
 (0)