From 47a5caef545581d7ee56692382ed556161dc257b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 7 Jul 2019 06:57:30 -0400 Subject: [PATCH] Fix last newline not being automatically appended Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/657 --- src/js/dyna-rules.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/dyna-rules.js b/src/js/dyna-rules.js index 92217ae78..839a9b4da 100644 --- a/src/js/dyna-rules.js +++ b/src/js/dyna-rules.js @@ -152,8 +152,10 @@ const rulesToDoc = function(clearHistory) { // https://github.com/uBlockOrigin/uBlock-issues/issues/593 // Ensure the text content always ends with an empty line to avoid // spurious diff entries. - let beforeText = doc.getValue().trim(); - if ( beforeText !== '' ) { beforeText += '\n'; } + // https://github.com/uBlockOrigin/uBlock-issues/issues/657 + // Diff against unmodified beforeText so that the last newline can + // be reported in the diff and thus appended if needed. + let beforeText = doc.getValue(); let afterText = rules.join('\n').trim(); if ( afterText !== '' ) { afterText += '\n'; } const diffs = differ.diff_main(beforeText, afterText);