diff --git a/src/dataCommand.ts b/src/dataCommand.ts index 7041776e..a747897e 100644 --- a/src/dataCommand.ts +++ b/src/dataCommand.ts @@ -238,13 +238,17 @@ export abstract class DataCommand extends SfdxCommand { const keyValuePairs: string[] = []; const trimmedText = text.trim(); + + const singleQuoteCount = (trimmedText.match(/'/g) || []).length; + const doubleQuoteCount = (trimmedText.match(/"/g) || []).length; + for (const currentChar of trimmedText) { - const isSeparator = separator.exec(currentChar); + const isSeparator = separator.test(currentChar); - if (currentChar === "'" && !inDoubleQuote) { + if (currentChar === "'" && !inDoubleQuote && singleQuoteCount >= 2) { inSingleQuote = !inSingleQuote; continue; - } else if (currentChar === '"' && !inSingleQuote) { + } else if (currentChar === '"' && !inSingleQuote && doubleQuoteCount >= 2) { inDoubleQuote = !inDoubleQuote; continue; } diff --git a/test/commands/force/data/dataCommand.test.ts b/test/commands/force/data/dataCommand.test.ts index 76cea47f..a91e0442 100644 --- a/test/commands/force/data/dataCommand.test.ts +++ b/test/commands/force/data/dataCommand.test.ts @@ -62,34 +62,46 @@ describe('dataCommand', () => { }); it('should allow single quotes in key=value pairs', () => { - const dict = dataCommand.testStringToDictionary('key1="val\'ue"'); + let dict = dataCommand.testStringToDictionary('key="val\'ue"'); expect(dict).to.deep.equal({ - key1: "val'ue", + key: "val'ue", + }); + + dict = dataCommand.testStringToDictionary("key=val'ue"); + + expect(dict).to.deep.equal({ + key: "val'ue", }); }); it('should allow double quotes in key=value pairs', () => { - const dict = dataCommand.testStringToDictionary("key1='val\"ue'"); + let dict = dataCommand.testStringToDictionary("key='val\"ue'"); + + expect(dict).to.deep.equal({ + key: 'val"ue', + }); + + dict = dataCommand.testStringToDictionary('key=val"ue'); expect(dict).to.deep.equal({ - key1: 'val"ue', + key: 'val"ue', }); }); it('should allow non alphanumeric characters in key=value pairs', () => { - const dict = dataCommand.testStringToDictionary('key1=!@#$%^&*()-_=+[{]}\\|;:,<.>/?`~'); + const dict = dataCommand.testStringToDictionary('key=!@#$%^&*()-_=+[{]}\\|;:,<.>/?`~'); expect(dict).to.deep.equal({ - key1: '!@#$%^&*()-_=+[{]}\\|;:,<.>/?`~', + key: '!@#$%^&*()-_=+[{]}\\|;:,<.>/?`~', }); }); it('should allow weird or foreign unicode characters in key=value pairs', () => { - const dict = dataCommand.testStringToDictionary('key1=♣♦♥♠&£ë╤è☺¼Φ╚↕↓㍿々'); + const dict = dataCommand.testStringToDictionary('key=♣♦♥♠&£ë╤è☺¼Φ╚↕↓㍿々'); expect(dict).to.deep.equal({ - key1: '♣♦♥♠&£ë╤è☺¼Φ╚↕↓㍿々', + key: '♣♦♥♠&£ë╤è☺¼Φ╚↕↓㍿々', }); }); });