Skip to content

Commit 80a3d69

Browse files
committed
Fix a cli command parsing bug
1 parent 729ebf9 commit 80a3d69

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/utils/mapshaper-utils.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,13 @@ export function trimQuotes(str) {
10721072
if (len >= 2) {
10731073
first = str.charAt(0);
10741074
last = str.charAt(len-1);
1075-
if (first == '"' && last == '"' && !str.includes('","') ||
1076-
first == "'" && last == "'" && !str.includes("','")) {
1075+
// if (first == '"' && last == '"' && !str.includes('","') ||
1076+
// first == "'" && last == "'" && !str.includes("','")) {
1077+
// don't strip if there are unescaped quotes
1078+
// e.g. expressions that start and end with quotes
1079+
// e.g. comma-separated list of quoted values
1080+
if (first == '"' && last == '"' && !/[^\\]"./.test(str) ||
1081+
first == "'" && last == "'" && !/[^\\]'./.test(str)) {
10771082
str = str.substr(1, len-2);
10781083
// remove string escapes
10791084
str = str.replace(first == '"' ? /\\(?=")/g : /\\(?=')/g, '');

test/utils-test.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ describe('mapshaper-utils.js', function () {
1818
// but only if entire string is quoted
1919
assert.equal(utils.trimQuotes(`\\"yes\\" or \\"no\\"`), `\\"yes\\" or \\"no\\"`);
2020
})
21+
22+
it('preserves certain expressions', function() {
23+
// shells seem to strip single quotes from expressions like: where='"hi" == "hi"'
24+
assert.equal(utils.trimQuotes(`"hi" == "hi"`), `"hi" == "hi"`);
25+
})
2126
})
2227

2328
describe('findQuantile()', function() {

0 commit comments

Comments
 (0)