Reverted solution for #794 due to undesirable side effects

This commit is contained in:
jos 2019-09-17 20:20:40 +02:00
parent 587db80d21
commit a60a1125ea
3 changed files with 5 additions and 15 deletions

View File

@ -3,12 +3,6 @@
https://github.com/josdejong/jsoneditor https://github.com/josdejong/jsoneditor
## not yet published, version 7.0.5
- Fix #794: fix discrepancy between valid JSON numbers and valid JavaScript
numbers (i.e. `+2` is a valid in JavaScript but not in JSON).
## 2019-09-11, version 7.0.4 ## 2019-09-11, version 7.0.4
- Fixed #723: schema error popup and color picker not always fully visible. - Fixed #723: schema error popup and color picker not always fully visible.

View File

@ -1345,14 +1345,10 @@ export function parseString (str) {
return false return false
} }
try { const num = Number(str) // will nicely fail with '123ab'
// will nicely fail for strings like '123ab', ' ', and '+1' const numFloat = parseFloat(str) // will nicely fail with ' '
const num = JSON.parse(str) if (!isNaN(num) && !isNaN(numFloat)) {
if (typeof num === 'number' && !isNaN(num)) { return num
return num
}
} catch (err) {
// no need to handle this error, it was just to try parsing into a number
} }
return str return str

View File

@ -399,7 +399,7 @@ describe('util', () => {
assert.strictEqual(parseString('null'), null) assert.strictEqual(parseString('null'), null)
assert.strictEqual(parseString('true'), true) assert.strictEqual(parseString('true'), true)
assert.strictEqual(parseString('false'), false) assert.strictEqual(parseString('false'), false)
assert.strictEqual(parseString('+1'), '+1') assert.strictEqual(parseString('+1'), 1)
assert.strictEqual(parseString(' '), ' ') assert.strictEqual(parseString(' '), ' ')
assert.strictEqual(parseString(''), '') assert.strictEqual(parseString(''), '')
assert.strictEqual(parseString('"foo"'), '"foo"') assert.strictEqual(parseString('"foo"'), '"foo"')