Merge pull request #186 from mikemorris/master
[#185,be/csv][xs]: fixing serializeCSV to pass test.
This commit is contained in:
@@ -179,7 +179,7 @@ this.recline.Backend.CSV = this.recline.Backend.CSV || {};
|
|||||||
if (field === null) {
|
if (field === null) {
|
||||||
// If field is null set to empty string
|
// If field is null set to empty string
|
||||||
field = '';
|
field = '';
|
||||||
} else if (typeof field === "string") {
|
} else if (typeof field === "string" && rxNeedsQuoting.test(field)) {
|
||||||
// Convert string to delimited string
|
// Convert string to delimited string
|
||||||
field = delimiter + field + delimiter;
|
field = delimiter + field + delimiter;
|
||||||
} else if (typeof field === "number") {
|
} else if (typeof field === "number") {
|
||||||
@@ -212,25 +212,6 @@ this.recline.Backend.CSV = this.recline.Backend.CSV || {};
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
var rxHasComma = /^\d+$/,
|
|
||||||
rxIsFloat = /^\d*\.\d+$|^\d+\.\d*$/,
|
|
||||||
// If a string has leading or trailing space,
|
|
||||||
// contains a comma double quote or a newline
|
|
||||||
// it needs to be quoted in CSV output
|
|
||||||
rxNeedsQuoting = /^\s|\s$|,|"|\n/,
|
|
||||||
trim = (function () {
|
|
||||||
// Fx 3.1 has a native trim function, it's about 10x faster, use it if it exists
|
|
||||||
if (String.prototype.trim) {
|
|
||||||
return function (s) {
|
|
||||||
return s.trim();
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return function (s) {
|
|
||||||
return s.replace(/^\s*/, '').replace(/\s*$/, '');
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
|
|
||||||
var rxIsInt = /^\d+$/,
|
var rxIsInt = /^\d+$/,
|
||||||
rxIsFloat = /^\d*\.\d+$|^\d+\.\d*$/,
|
rxIsFloat = /^\d*\.\d+$|^\d+\.\d*$/,
|
||||||
// If a string has leading or trailing space,
|
// If a string has leading or trailing space,
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ test("serializeCSV", function() {
|
|||||||
|
|
||||||
var array = recline.Backend.CSV.serializeCSV(csv);
|
var array = recline.Backend.CSV.serializeCSV(csv);
|
||||||
var exp = '"Jones, Jay",10\n' +
|
var exp = '"Jones, Jay",10\n' +
|
||||||
'"Xyz ""ABC"" O\'Brien",11:35\n' +
|
'"Xyz \"ABC\" O\'Brien",11:35\n' +
|
||||||
'"Other, AN",12:35\n';
|
'"Other, AN",12:35\n';
|
||||||
deepEqual(array, exp);
|
deepEqual(array, exp);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user