Fix parsing and writing of empty values.

Also, fix other parsing issues.
This commit is contained in:
Mike Stegeman 2017-10-30 06:37:16 -06:00 committed by Andre Natal
parent 9d334161bc
commit e0a28b434e
1 changed files with 9 additions and 18 deletions

View File

@ -36,7 +36,7 @@ function parsePythonConf(str, cb) {
if (!line) { return; }
var parts = line.trim().split('=');
var parts = line.split('=');
var pykey = parts.shift().trim();
var key = camelCase(pykey);
var val = parts.join('=').trim();
@ -47,13 +47,13 @@ function parsePythonConf(str, cb) {
else if ('False' === val) {
val = false;
}
else if ('None' === val) {
else if ('None' === val || '' === val) {
val = null;
}
else if (/,/.test(val) && !/^"[^"]*"$/.test(val)) {
val = val.split(',');
val = val.split(',').map(function(x) { return x.trim(); });
}
else if (/^[0-9]+$/.test(val)) {
else if (/^-?[0-9]+$/.test(val)) {
val = parseInt(val, 10);
}
@ -91,7 +91,7 @@ function toPyVal(val) {
else if (Array.isArray(val)) {
val = val.join(',');
if (-1 === val.indexOf(',')) {
val += ','; // disambguates value from array with one element
val += ','; // disambiguates value from array with one element
}
return val;
}
@ -119,9 +119,10 @@ function stringifyPythonConf(obj, cb) {
if ('undefined' === typeof pyval) {
if ('number' === typeof num) {
obj.__lines[num] = "___DELETE_ME___";
pyval = '';
} else {
return;
}
return;
}
if ('number' !== typeof num) {
@ -145,17 +146,7 @@ function stringifyPythonConf(obj, cb) {
comment = obj.__lines[num].replace(/.*?(\s*#.*)/, '$1');
}
if ('undefined' === typeof pyval) {
obj.__lines[num] = "___DELETE_ME___";
} else {
obj.__lines[num] = pykey + ' = ' + pyval + comment;
}
});
obj.__lines = obj.__lines.filter(function (line) {
if ("___DELETE_ME___" !== line) {
return true;
}
obj.__lines[num] = pykey + ' = ' + pyval + comment;
});
if ('string' === typeof endline) {