Skip to content

Commit 9dfacb2

Browse files
committed
Corrected the float specification as per spec and Lee Byrons direction
1 parent 71f6fcd commit 9dfacb2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/antlr/Graphql.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ NAME: [_A-Za-z][_0-9A-Za-z]*;
199199

200200
IntValue : Sign? IntegerPart;
201201

202-
FloatValue : Sign? IntegerPart ('.' Digit*)? ExponentPart?;
202+
FloatValue : Sign? IntegerPart ('.' Digit+)? ExponentPart?;
203203

204204
Sign : '-';
205205

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ class ParserTest extends Specification {
313313
given:
314314
def input = """
315315
query myQuery {
316-
hello(arg: {intKey:1, floatKey: 4., stringKey: \"world\", subObject: {subKey:true} } ) }
316+
hello(arg: {intKey:1, floatKey: 4.1, stringKey: \"world\", subObject: {subKey:true} } ) }
317317
"""
318318

319319
and: "expected query"
320320

321321
def objectValue = new ObjectValue()
322322
objectValue.getObjectFields().add(new ObjectField("intKey", new IntValue(1)))
323-
objectValue.getObjectFields().add(new ObjectField("floatKey", new FloatValue(4)))
323+
objectValue.getObjectFields().add(new ObjectField("floatKey", new FloatValue(4.1)))
324324
objectValue.getObjectFields().add(new ObjectField("stringKey", new StringValue("world")))
325325
def subObject = new ObjectValue()
326326
subObject.getObjectFields().add(new ObjectField("subKey", new BooleanValue(true)))
@@ -379,6 +379,18 @@ class ParserTest extends Specification {
379379

380380
}
381381

382+
def "#848 floats must have digits"() {
383+
given:
384+
def input = """
385+
{ hello(arg: 4.) }
386+
"""
387+
when:
388+
def document = new Parser().parseDocument(input)
389+
390+
then:
391+
thrown(ParseCancellationException)
392+
}
393+
382394
def "extraneous input is an exception"() {
383395
given:
384396
def input = """

0 commit comments

Comments
 (0)