Avoid parsing version properties as numbers

Parsing versions such as "1.10" results in a "1.1" float, incorrectly
changing the value.

Fixes #1980
This commit is contained in:
Kale Blankenship
2020-05-17 11:12:17 -07:00
committed by Austin Morton
parent df27a15b57
commit e8c754d830
3 changed files with 17 additions and 2 deletions

View File

@@ -68,8 +68,15 @@ function parseProperties(blob, name) {
logger.error(`Bad line: ${line} in ${name}: ${index + 1}`);
return;
}
props[split[1].trim()] = toProperty(split[2].trim());
debug(`${split[1].trim()} = ${split[2].trim()}`);
let prop = split[1].trim();
let val = split[2].trim();
// hack to avoid applying toProperty to version properties
// so that they're not parsed as numbers
if (!prop.endsWith('.version') && !prop.endsWith('.semver')) {
val = toProperty(val);
}
props[prop] = val;
debug(`${prop} = ${val}`);
});
return props;
}

View File

@@ -20,3 +20,5 @@ stringPropertyFalse=False
badLineIfYouSeeThisWithAnErrorItsOk
001string=001
0985string=0985
compiler.example110.semver=1.10
libs.example.versions.010.version=0.10

View File

@@ -151,6 +151,12 @@ describe('Properties', () => {
compilerProps.get(languages, 'bar', true, undefined).should.deep.equal({a: false});
compilerProps.propsByLangId[languages.a.id] = undefined;
});
it('should not parse version properies as numbers', () => {
should.equal(casesProps('libs.example.versions.010.version'), '0.10');
});
it('should not parse semver properies as numbers', () => {
should.equal(casesProps('compiler.example110.semver'), '1.10');
});
});
describe('Properties blob parsing', () => {