Fix parsing and writing of empty values.
Also, fix other parsing issues.
This commit is contained in:
parent
9d334161bc
commit
e0a28b434e
25
index.js
25
index.js
|
@ -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,10 +119,11 @@ function stringifyPythonConf(obj, cb) {
|
|||
|
||||
if ('undefined' === typeof pyval) {
|
||||
if ('number' === typeof num) {
|
||||
obj.__lines[num] = "___DELETE_ME___";
|
||||
}
|
||||
pyval = '';
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ('number' !== typeof num) {
|
||||
obj.__lines.push(pykey + ' = ' + pyval);
|
||||
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
if ('string' === typeof endline) {
|
||||
|
|
Loading…
Reference in New Issue