Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: quote() should include newline in literal #47

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ test`;
});

it("should write out text surrounded by quotes and escape quotes and new lines", () => {
const expected = `"te\\"\\\r\nst"`;
const expected = `"te\\"\\r\\n\\\r\nst"`;
doTest(expected, writer => {
writer.quote("te\"\r\nst");
});
Expand Down Expand Up @@ -1155,7 +1155,7 @@ describe("#hangingIndent", () => {
writer.hangingIndent(() => {
writer.quote("t\nu").newLine().write("t");
});
expect(writer.toString()).to.equal(`"t\\\nu"\n t`);
expect(writer.toString()).to.equal(`"t\\n\\\nu"\n t`);
});
});

Expand Down
2 changes: 1 addition & 1 deletion utils/string_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("escapeForWithinString", () => {
}

it("should escape the quotes and newline", () => {
doTest(`"testing\n this out"`, `\\"testing\\\n this out\\"`);
doTest(`"testing\n this out"`, `\\"testing\\n\\\n this out\\"`);
});

function doQuoteTest(input: string, quote: string, expected: string) {
Expand Down
4 changes: 2 additions & 2 deletions utils/string_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export function escapeForWithinString(str: string, quoteKind: string) {
if (str[i] === quoteKind) {
result += "\\";
} else if (str[i] === "\r" && str[i + 1] === "\n") {
result += "\\";
result += "\\r\\n\\";
i++; // skip the \r
} else if (str[i] === "\n") {
result += "\\";
result += "\\n\\";
} else if (str[i] === "\\") {
result += "\\";
}
Expand Down
Loading