Skip to content

Commit

Permalink
Reverted solution for josdejong#794 due to undesirable side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Sep 17, 2019
1 parent 587db80 commit a60a112
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
6 changes: 0 additions & 6 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
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

- Fixed #723: schema error popup and color picker not always fully visible.
Expand Down
12 changes: 4 additions & 8 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1345,14 +1345,10 @@ export function parseString (str) {
return false
}

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

return str
Expand Down
2 changes: 1 addition & 1 deletion test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ describe('util', () => {
assert.strictEqual(parseString('null'), null)
assert.strictEqual(parseString('true'), true)
assert.strictEqual(parseString('false'), false)
assert.strictEqual(parseString('+1'), '+1')
assert.strictEqual(parseString('+1'), 1)
assert.strictEqual(parseString(' '), ' ')
assert.strictEqual(parseString(''), '')
assert.strictEqual(parseString('"foo"'), '"foo"')
Expand Down

0 comments on commit a60a112

Please sign in to comment.