Open vlasky opened 8 years ago
I didn't even think about the null
JSON string since all the other data types use the same output for null values.
diff --git a/test/types.js b/test/types.js
index a8c1302..412b41f 100644
--- a/test/types.js
+++ b/test/types.js
@@ -357,6 +357,8 @@ defineTypeTest('datetime_then_decimal', [
defineTypeTest('json', [
'JSON NULL'
], [
+ ['\'null\''],
+ ['\'{"key1": null}\''],
// Small Object
['\'{"key1": "value1", "key2": "value2", "key3": 34}\''],
// Small Object with nested object
Adding these to the JSON type test does not cause it to fail against master
. I don't know how to reproduce this.
A JSON string cannot be empty it seems:
> JSON.parse('')
SyntaxError: Unexpected end of JSON input
at Object.parse (native)
at repl:1:6
at REPLServer.defaultEval (repl.js:272:27)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:441:10)
at emitOne (events.js:101:20)
at REPLServer.emit (events.js:188:7)
at REPLServer.Interface._onLine (readline.js:219:10)
at REPLServer.Interface._line (readline.js:561:8)
> JSON.parse('null')
null
I confirm that my proposed fix solved the problem.
Our use case was:
That is sufficient to cause the RangeError.
That scenario does not cause an error. This type test passes:
defineTypeTest('int_and_json', [
'INT SIGNED NULL',
'JSON NULL'
], [
[ 5, null ],
[ null, '\'null\'' ],
[ 7, '\'null\'' ],
], '5.7.8');
When we insert a new row into a table with a JSON column that is empty or null, we get an error like this that causes MeteorJS to exit:
I believe the problem lies in line 55 of function parseBinaryBuffer() of /lib/json_decode.js
var jsonType = input.readUInt8(offset);
There are no prior checks to ensure that input is not empty before executing this line of code. I would fix this by inserting a line just above with the following check :
if (input.length === 0) return null;