Merge pull request #4361 from CatoTH/OS3-Diff-Bugfix-With-Newlines

Diff-Bugfix: Newlines and split paragraphs
This commit is contained in:
Emanuel Schütze 2019-02-18 09:40:04 +01:00 committed by GitHub
commit 1920eb18c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -809,6 +809,24 @@ describe('DiffService', () => {
); );
})); }));
it('does not like splitting paragraphs too much, but respects line breaks between paragraphs', inject(
[DiffService],
(service: DiffService) => {
const before =
'<P>Bavaria ipsum dolor sit amet oha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher. Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.</P>',
after =
'<p>Bavaria ipsum dolor sit amet oha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher.</p>\n<p>Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.';
const diff = service.diff(before, after);
expect(diff).toBe(
'<P class="delete">Bavaria ipsum dolor sit amet oha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher. Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.</P>' +
'<P class="insert">Bavaria ipsum dolor sit amet oha wea nia ausgähd, kummt nia hoam i hob di narrisch gean helfgod ebba ded baddscher.</P>' +
'<INS>\n</INS>' +
'<P class="insert">Des so so, nia Biawambn back mas? Kaiwe Hetschapfah Trachtnhuat, a bravs.</P>'
);
}
));
it('does not repeat the last word (1)', inject([DiffService], (service: DiffService) => { it('does not repeat the last word (1)', inject([DiffService], (service: DiffService) => {
const before = '<P>sem. Nulla consequat massa quis enim. </P>', const before = '<P>sem. Nulla consequat massa quis enim. </P>',
after = '<p>sem. Nulla consequat massa quis enim. TEST<br>\nTEST</p>'; after = '<p>sem. Nulla consequat massa quis enim. TEST<br>\nTEST</p>';

View File

@ -939,8 +939,8 @@ export class DiffService {
private diffDetectBrokenDiffHtml(html: string): boolean { private diffDetectBrokenDiffHtml(html: string): boolean {
// If other HTML tags are contained within INS/DEL (e.g. "<ins>Test</p></ins>"), let's better be cautious // 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 :) // The "!!(found=...)"-construction is only used to make jshint happy :)
const findDel = /<del>(.*?)<\/del>/gi, const findDel = /<del>([\s\S]*?)<\/del>/gi,
findIns = /<ins>(.*?)<\/ins>/gi; findIns = /<ins>([\s\S]*?)<\/ins>/gi;
let found, inner; let found, inner;
while (!!(found = findDel.exec(html))) { while (!!(found = findDel.exec(html))) {
inner = found[1].replace(/<br[^>]*>/gi, ''); inner = found[1].replace(/<br[^>]*>/gi, '');