From ff857c50974ad25ed926535017f8fe5b9fd1c530 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Mon, 14 Sep 2020 15:02:36 -0400 Subject: [PATCH] Bug 1664888 - Replace \n and \r by \n and \r when saving a string. r=bdahl, a=RyanVM This is a cherry-pick of the following upstream commit: https://github.com/mozilla/pdf.js/pull/12374 Differential Revision: https://phabricator.services.mozilla.com/D90154 --- toolkit/components/pdfjs/content/build/pdf.js | 10 +++++++++- toolkit/components/pdfjs/content/build/pdf.worker.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/toolkit/components/pdfjs/content/build/pdf.js b/toolkit/components/pdfjs/content/build/pdf.js index 1d9b1052841ab..85b40585ce134 100644 --- a/toolkit/components/pdfjs/content/build/pdf.js +++ b/toolkit/components/pdfjs/content/build/pdf.js @@ -1576,7 +1576,15 @@ function stringToPDFString(str) { } function escapeString(str) { - return str.replace(/([\(\)\\])/g, "\\$1"); + return str.replace(/([\(\)\\\n\r])/g, match => { + if (match === "\n") { + return "\\n"; + } else if (match === "\r") { + return "\\r"; + } + + return `\\${match}`; + }); } function stringToUTF8String(str) { diff --git a/toolkit/components/pdfjs/content/build/pdf.worker.js b/toolkit/components/pdfjs/content/build/pdf.worker.js index a4171feef63ab..5d05e537d30c6 100644 --- a/toolkit/components/pdfjs/content/build/pdf.worker.js +++ b/toolkit/components/pdfjs/content/build/pdf.worker.js @@ -1485,7 +1485,15 @@ function stringToPDFString(str) { } function escapeString(str) { - return str.replace(/([\(\)\\])/g, "\\$1"); + return str.replace(/([\(\)\\\n\r])/g, match => { + if (match === "\n") { + return "\\n"; + } else if (match === "\r") { + return "\\r"; + } + + return `\\${match}`; + }); } function stringToUTF8String(str) {