Skip to content

Commit c2a48dc

Browse files
author
Laszlo Radics
committed
fix: array column parsing , JSON.parse do not handle correctly special characters ex: \ f (formfeed)
1 parent c171155 commit c2a48dc

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

lib/pgConverters.js

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/pgConverters.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/pgConverters.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export let arraySplit = (str) => {
1010
do {
1111
parsingResult = e.exec(str);
1212
let valStr = (parsingResult[2] == 'NULL') ? null :
13-
(parsingResult[1] == null ? parsingResult[2] : JSON.parse(parsingResult[1])); // for string parsing, escape \
13+
(parsingResult[1] == null ? parsingResult[2] : unescapeString(parsingResult[1])); // for string parsing, escape \
1414
valList.push(valStr);
1515
} while (e.lastIndex < str.length);
1616
return valList;
@@ -30,3 +30,9 @@ export let arraySplitToJson = (str) => {
3030
let vals = arraySplit(str);
3131
return vals.map(s=> typeof s === 'string' ? JSON.parse(s) : s);
3232
};
33+
34+
function unescapeString(s) {
35+
return s.slice(1, s.length - 1) // cut the first and the last "
36+
.replace(/\\"/g, '"') // \" -> "
37+
.replace(/\\\\/g, '\\') // \\ -> \
38+
}

src/test/pgDbSpec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ describe("pgdb", () => {
764764
}));
765765

766766
it("Testing text array parsing", w(async () => {
767-
let list = ["'A'", '"A"', 'normal', '//', '\\', '""', "''", '--', '/*', '', '<!--', JSON.stringify({
767+
let list = ["'A'", '"A"', 'normal', '//', '\\','\\\\\\"','\\\\"','\\"', '""', "''", '--', '/*', '', '<!--', JSON.stringify({
768768
a: 1,
769769
b: "aprocska\"kalapocska'bennecsacskamacskamocska"
770770
})];

0 commit comments

Comments
 (0)