Skip to content

Commit

Permalink
Fix js translator only escaping first occurance of single-quote CTR
Browse files Browse the repository at this point in the history
  • Loading branch information
Cole-Greer committed Dec 6, 2024
1 parent cc74c84 commit d01160a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.\'))');
});
});
});

0 comments on commit d01160a

Please sign in to comment.