From 3870ec17efa1af933e20342f005c77726a6546d1 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Tue, 18 Jun 2024 09:01:36 +0200 Subject: [PATCH] fix: #1601 do not convert hexadecimal values into regular numbers --- src/js/util.js | 5 ++++- test/util.test.js | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/js/util.js b/src/js/util.js index e41933bc..0bec91f5 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -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 } diff --git a/test/util.test.js b/test/util.test.js index db0476a7..32bf14f0 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -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', () => {