Skip to content

Commit 5dcd18f

Browse files
committed
Avoid 0X.. property values to be parsed as ints
It might break 3rd party configs in some obscure way, but after looking at how it might happen, I can't see obvious reasons not to implement it
1 parent 63de746 commit 5dcd18f

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/properties.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function get(base, property, defaultValue) {
6060
function toProperty(prop) {
6161
if (prop === 'true' || prop === 'yes') return true;
6262
if (prop === 'false' || prop === 'no') return false;
63-
if (prop.match(/^-?[0-9]+$/)) return parseInt(prop);
63+
if (prop.match(/^-?(0|[1-9][0-9]*)$/)) return parseInt(prop);
6464
if (prop.match(/^-?[0-9]*\.[0-9]+$/)) return parseFloat(prop);
6565
return prop;
6666
}

test/example-config/cases.test.properties

+2
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ falsePropertyFalse=false
1818
stringPropertyNo=No
1919
stringPropertyFalse=False
2020
badLineIfYouSeeThisWithAnErrorItsOk
21+
001string=001
22+
0985string=0985

test/properties-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ describe('Properties', () => {
4646
it('Handles empty properties as empty strings', () => {
4747
should.equal(casesProps("emptyProperty"), "");
4848
});
49+
it('Handles bad numbers properties as strings', () => {
50+
should.equal(casesProps("001string"), "001");
51+
});
52+
it('Handles bad numbers properties as strings', () => {
53+
should.equal(casesProps("0985string"), "0985");
54+
});
4955
it('Ignores commented out properties', () => {
5056
should.equal(casesProps("commentedProperty"), undefined);
5157
});

0 commit comments

Comments
 (0)