1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-14 23:12:28 +02:00

Fix last newline not being automatically appended

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/657
This commit is contained in:
Raymond Hill 2019-07-07 06:57:30 -04:00
parent 9d1913a16e
commit 47a5caef54
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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);