Skip to content

Commit

Permalink
[(develop)] fixed parseString when it trimming zero in the beggining (#…
Browse files Browse the repository at this point in the history
…1549)

* [(develop)] fixed parseString when it trimming zero in the beggining of value

* [(develop)] added one more test

* [(develop)] fixed leading zero removing

* [(develop)] fixed lint error

---------

Co-authored-by: Viacheslav Lopatynskyi <viacheslav.lopatynskyi@systematic.com>
  • Loading branch information
DarkFisk and Viacheslav Lopatynskyi committed Sep 21, 2023
1 parent 228dd2e commit 77246fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,10 @@ export function parseString (str) {
return false
}

if (/^0\d+$/.test(str)) { // to treat '001' as a string
return str
}

const num = Number(str) // will nicely fail with '123ab'
const numFloat = parseFloat(str) // will nicely fail with ' '
if (!isNaN(num) && !isNaN(numFloat)) {
Expand Down
4 changes: 4 additions & 0 deletions test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ describe('util', () => {
assert.strictEqual(parseString('true'), true)
assert.strictEqual(parseString('false'), false)
assert.strictEqual(parseString('+1'), 1)
assert.strictEqual(parseString('01'), '01')
assert.strictEqual(parseString('001'), '001')
assert.strictEqual(parseString('0.3'), 0.3)
assert.strictEqual(parseString('0e3'), 0)
assert.strictEqual(parseString(' '), ' ')
assert.strictEqual(parseString(''), '')
assert.strictEqual(parseString('"foo"'), '"foo"')
Expand Down

0 comments on commit 77246fc

Please sign in to comment.