From 582645df70a3b9e61628988756f483061c04a924 Mon Sep 17 00:00:00 2001 From: jos Date: Sun, 16 Feb 2020 10:11:12 +0100 Subject: [PATCH] Fix replacing Python constants in arrays --- src/js/util.js | 5 ++++- test/util.test.js | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/js/util.js b/src/js/util.js index ffb7349..5fc365b 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -179,7 +179,9 @@ export function repair (jsString) { c = curr() } - if (specialValues.indexOf(key) === -1) { + if (key in pythonConstants) { + return pythonConstants[key] + } else if (specialValues.indexOf(key) === -1) { return '"' + key + '"' } else { return key @@ -268,6 +270,7 @@ export function repair (jsString) { i++ } else if (/[a-zA-Z_$]/.test(c) && ['{', ','].indexOf(lastNonWhitespace()) !== -1) { // an unquoted object key (like a in '{a:2}') + // FIXME: array values are also parsed via parseKey, work this out properly chars.push(parseKey()) } else if (/\w/.test(c)) { chars.push(parseValue()) diff --git a/test/util.test.js b/test/util.test.js index 715be60..6b03ac4 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -141,12 +141,14 @@ describe('util', () => { ' "null": None,\n' + ' "true": True,\n' + ' "false": False\n' + + ' "array": [1, foo, None, True, False]\n' + '}' const expectedJson = '{\n' + ' "null": null,\n' + ' "true": true,\n' + ' "false": false\n' + + ' "array": [1, "foo", null, true, false]\n' + '}' assert.strictEqual(repair(pythonDocument), expectedJson)