diff --git a/mod.test.ts b/mod.test.ts index d2b61ee..199223c 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -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"); }); @@ -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`); }); }); diff --git a/utils/string_utils.test.ts b/utils/string_utils.test.ts index b3a9033..cc15c0e 100644 --- a/utils/string_utils.test.ts +++ b/utils/string_utils.test.ts @@ -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) { diff --git a/utils/string_utils.ts b/utils/string_utils.ts index ba561e8..c21cc34 100644 --- a/utils/string_utils.ts +++ b/utils/string_utils.ts @@ -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 += "\\"; }