mirror of https://github.com/hyper-tuner/ini.git
Better string sanitization
This commit is contained in:
parent
f0cffb2d04
commit
d142f37114
|
@ -1135,9 +1135,14 @@ export class INI {
|
|||
.tryParse(line);
|
||||
}
|
||||
|
||||
private static numberOrExpression = (val: string | undefined | null) => INI.isNumber(val || '0') ? Number(val || 0) : INI.sanitize(`${val}`);
|
||||
private static numberOrExpression = (val: string | undefined | null) =>
|
||||
INI.isNumber(val || '0') ? Number(val || 0) : INI.sanitize(`${val}`);
|
||||
|
||||
private static sanitize = (val: any) => val === undefined ? '' : `${val}`.replace(/"/g, '').trim();
|
||||
private static sanitize = (val: any) =>
|
||||
val === undefined ? '' : `${val}`
|
||||
.replace(/"/g, '')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
|
||||
private static isNumber = (val: any) => !Number.isNaN(Number(val));
|
||||
|
||||
|
|
|
@ -47,9 +47,9 @@ VERSIONS.forEach((version) => {
|
|||
fs.writeFileSync(pathFor(`tmp/${version}.yml`), yamlContent);
|
||||
fs.writeFileSync(pathFor(`tmp/${version}.json`), jsonContent);
|
||||
|
||||
assert.equal(yamlNew, yamlOld);
|
||||
assert.equal(jsonNew, jsonOld);
|
||||
assert.equal(yamlNew, yamlOld, `Generated file ${version}.yaml looks different than expected`);
|
||||
assert.equal(jsonNew, jsonOld, `Generated file ${version}.json looks different than expected`);
|
||||
|
||||
fs.unlinkSync(pathFor(`tmp/${version}.yml`));
|
||||
fs.unlinkSync(pathFor(`tmp/${version}.json`));
|
||||
// fs.unlinkSync(pathFor(`tmp/${version}.yml`));
|
||||
// fs.unlinkSync(pathFor(`tmp/${version}.json`));
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue