diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/translator.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/translator.js index 7eceb258c4..fb58907cf1 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/translator.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/translator.js @@ -91,7 +91,7 @@ class Translator { } script += `('${key}', `; if (anyObject[key] instanceof String || typeof anyObject[key] === 'string') { - script += `'${anyObject[key]}'`; + script += `'${`${anyObject[key]}`.replaceAll("'", "\\'")}'`; // eslint-disable-line quotes } else { script += anyObject[key]; } @@ -111,7 +111,7 @@ class Translator { } else if (typeof anyObject === 'number' || typeof anyObject === 'boolean') { script += anyObject; } else { - script += `'${`${anyObject}`.replace("'", "\\'")}'`; // eslint-disable-line quotes + script += `'${`${anyObject}`.replaceAll("'", "\\'")}'`; // eslint-disable-line quotes } return script; diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/translator-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/translator-test.js index 986dbd161a..a91742fc25 100644 --- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/translator-test.js +++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/translator-test.js @@ -133,5 +133,13 @@ describe('Translator', function () { assert.ok(script); assert.strictEqual(script, 'g.addV(\'test\').property(\'quotes\', \'some "quotes\\\' in the middle.\')'); }); + + it('should properly escape quotes in Object values', function () { + const g = new graph.Graph().traversal(); + const o = {key: "some \"quotes' in the middle."} + const script = new Translator('g').translate(g.inject(o)); + assert.ok(script); + assert.strictEqual(script, 'g.inject((\'key\', \'some "quotes\\\' in the middle.\'))'); + }); }); });