Skip to content

Commit

Permalink
fix: #1601 do not convert hexadecimal values into regular numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jun 18, 2024
1 parent 1e38adf commit 3870ec1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,10 @@ export function parseString (str) {
return false
}

if (/^0\d+$/.test(str)) { // to treat '001' as a string
const containsLeadingZero = /^0\d+$/
const startsWithZeroPrefix = /^0[xbo]/ // hex, binary, octal numbers
if (containsLeadingZero.test(str) || startsWithZeroPrefix.test(str)) {
// treat '001', '0x1A', '0b1101', and '0o3700' as a string
return str
}

Expand Down
5 changes: 5 additions & 0 deletions test/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ describe('util', () => {
assert.strictEqual(parseString('"foo"'), '"foo"')
assert.strictEqual(parseString('"2"'), '"2"')
assert.strictEqual(parseString('\'foo\''), '\'foo\'')
assert.strictEqual(parseString('0x1A'), '0x1A')
assert.strictEqual(parseString('0x1F'), '0x1F')
assert.strictEqual(parseString('0x1a'), '0x1a')
assert.strictEqual(parseString('0b1101'), '0b1101')
assert.strictEqual(parseString('0o3700'), '0o3700')
})

it('should find a unique name', () => {
Expand Down

0 comments on commit 3870ec1

Please sign in to comment.