From a345815b57114fcd23507723eaff6cdd14c09b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?= Date: Tue, 13 Feb 2018 16:43:07 +0100 Subject: [PATCH] Escape Ampersands - fixes #3563 --- openslides/motions/static/js/motions/diff.js | 12 ++++++------ tests/karma/motions/diff.service.test.js | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/openslides/motions/static/js/motions/diff.js b/openslides/motions/static/js/motions/diff.js index a9da86782..486ed936c 100644 --- a/openslides/motions/static/js/motions/diff.js +++ b/openslides/motions/static/js/motions/diff.js @@ -185,17 +185,17 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi }; this._serializeDom = function(node, stripLineNumbers) { - if (node.nodeType == TEXT_NODE) { + if (node.nodeType === TEXT_NODE) { return node.nodeValue.replace(//g, ">"); } if (stripLineNumbers && ( lineNumberingService._isOsLineNumberNode(node) || lineNumberingService._isOsLineBreakNode(node))) { return ''; } - if (node.nodeName == 'OS-LINEBREAK') { + if (node.nodeName === 'OS-LINEBREAK') { return ''; } - if (node.nodeName == 'BR') { + if (node.nodeName === 'BR') { var br = '/g, ">"); + if (node.childNodes[i].nodeType === TEXT_NODE) { + html += node.childNodes[i].nodeValue.replace(/&/g, "&").replace(//g, ">"); } else if (!stripLineNumbers || (!lineNumberingService._isOsLineNumberNode(node.childNodes[i]) && !lineNumberingService._isOsLineBreakNode(node.childNodes[i]))) { html += this._serializeDom(node.childNodes[i], stripLineNumbers); } } - if (node.nodeType != DOCUMENT_FRAGMENT_NODE) { + if (node.nodeType !== DOCUMENT_FRAGMENT_NODE) { html += ''; } diff --git a/tests/karma/motions/diff.service.test.js b/tests/karma/motions/diff.service.test.js index adbfb6b32..ef354b675 100644 --- a/tests/karma/motions/diff.service.test.js +++ b/tests/karma/motions/diff.service.test.js @@ -300,6 +300,13 @@ describe('linenumbering', function () { expect(containsError).toBe(-1); expect(containsCorrectVersion > 0).toBe(true); }); + + it('keeps ampersands escaped', function() { + var pre = '

' + noMarkup(1) + 'foo & bar

', + after = '

' + noMarkup(1) + 'foo & bar ins

'; + var merged = diffService.replaceLines(pre, after, 1, 2, true); + expect(merged).toBe('

foo & bar ins

'); + }); }); describe('detecting the type of change', function() {