Skip to content

Commit

Permalink
Fix StringUtils.ensureQuoted to escape multiple quotations (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanBoltonMN authored Apr 5, 2024
1 parent a92d1f0 commit 6a2dcc8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/powerquery-parser",
"version": "0.15.9",
"version": "0.15.10",
"description": "A parser for the Power Query/M formula language.",
"author": "Microsoft",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/common/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function ensureQuoted(text: string): string {
return text;
}

return `"${text.includes(`"`) ? text.replace(`"`, `""`) : text}"`;
return `"${text.replace(/"/g, '""')}"`;
}

export function columnNumberFrom(text: string, requiredCodeUnit: number): number {
Expand Down
1 change: 1 addition & 0 deletions src/test/libraryTest/common/stringUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("StringUtils", () => {
it(`"`, () => expect(StringUtils.ensureQuoted(`"`)).to.equal(`""""`));
it(`""`, () => expect(StringUtils.ensureQuoted(`""`)).to.equal(`""`));
it(`"a"`, () => expect(StringUtils.ensureQuoted(`"a"`)).to.equal(`"a"`));
it(`a"b"c`, () => expect(StringUtils.ensureQuoted(`a"b"c`)).to.equal(`"a""b""c"`));
});

describe(`findQuote`, () => {
Expand Down

0 comments on commit 6a2dcc8

Please sign in to comment.