Skip to content

Commit 4288c19

Browse files
astFromValue: reject non-finite numbers (#2437)
1 parent 4449dde commit 4288c19

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/utilities/__tests__/astFromValue-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ describe('astFromValue', () => {
205205
value: 'value',
206206
});
207207

208+
expect(astFromValue(NaN, passthroughScalar)).to.equal(null);
209+
expect(() => astFromValue(Infinity, passthroughScalar)).to.throw(
210+
'Cannot convert value to AST: Infinity.',
211+
);
212+
208213
const returnNullScalar = new GraphQLScalarType({
209214
name: 'ReturnNullScalar',
210215
serialize() {

src/utilities/astFromValue.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow strict
22

3+
import isFinite from '../polyfills/isFinite';
34
import arrayFrom from '../polyfills/arrayFrom';
45
import objectValues from '../polyfills/objectValues';
56

@@ -116,7 +117,7 @@ export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode {
116117
}
117118

118119
// JavaScript numbers can be Int or Float values.
119-
if (typeof serialized === 'number') {
120+
if (typeof serialized === 'number' && isFinite(serialized)) {
120121
const stringNum = String(serialized);
121122
return integerStringRegExp.test(stringNum)
122123
? { kind: Kind.INT, value: stringNum }

0 commit comments

Comments
 (0)