Prevent broken HTML like <ins>Test</p></ins>
This commit is contained in:
parent
9f71afa602
commit
a6de228f56
@ -890,6 +890,22 @@ angular.module('OpenSlidesApp.motions.diff', ['OpenSlidesApp.motions.lineNumberi
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If other HTML tags are contained within INS/DEL (e.g. "<ins>Test</p></ins>"), let's better be cautious
|
||||||
|
// The "!!(found=...)"-construction is only used to make jshint happy :)
|
||||||
|
var findDel = /<del>(.*?)<\/del>/gi,
|
||||||
|
findIns = /<ins>(.*?)<\/ins>/gi,
|
||||||
|
found;
|
||||||
|
while (!!(found = findDel.exec(html))) {
|
||||||
|
if (found[1].match(/<[^>]*>/)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (!!(found = findIns.exec(html))) {
|
||||||
|
if (found[1].match(/<[^>]*>/)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If too much of the text is changed, it's better to separate the old from new new version,
|
// If too much of the text is changed, it's better to separate the old from new new version,
|
||||||
// otherwise the result looks strange
|
// otherwise the result looks strange
|
||||||
if (this._calcChangeRatio(html) > 0.66) {
|
if (this._calcChangeRatio(html) > 0.66) {
|
||||||
|
@ -390,6 +390,19 @@ describe('linenumbering', function () {
|
|||||||
expect(diff).toBe(expected);
|
expect(diff).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles inserted paragraphs (2)', function () {
|
||||||
|
// Specifically, Noch</p> should not be enclosed by <ins>...</ins>, as <ins>Noch </p></ins> would be seriously broken
|
||||||
|
var before = "<P>rief sie alle sieben herbei und sprach 'liebe Kinder, ich will hinaus in den Wald, seid </P>",
|
||||||
|
after = "<p>rief sie alle sieben herbei und sprach 'liebe Kinder, ich will hinaus in den Wald, seid Noch</p>" +
|
||||||
|
"<p>Test 123</p>",
|
||||||
|
expected = "<P class=\"delete\">rief sie alle sieben herbei und sprach 'liebe Kinder, ich will hinaus in den Wald, seid </P>" +
|
||||||
|
"<P class=\"insert\">rief sie alle sieben herbei und sprach 'liebe Kinder, ich will hinaus in den Wald, seid Noch</P>" +
|
||||||
|
"<P class=\"insert\">Test 123</P>";
|
||||||
|
|
||||||
|
var diff = diffService.diff(before, after);
|
||||||
|
expect(diff).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('handles completely deleted paragraphs', function () {
|
it('handles completely deleted paragraphs', function () {
|
||||||
var before = "<P>Ihr könnt ohne Sorge fortgehen.'Da meckerte die Alte und machte sich getrost auf den Weg.</P>",
|
var before = "<P>Ihr könnt ohne Sorge fortgehen.'Da meckerte die Alte und machte sich getrost auf den Weg.</P>",
|
||||||
after = "";
|
after = "";
|
||||||
|
Loading…
Reference in New Issue
Block a user