File tree Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ CHANGELOG Roundcube Webmail
12
12
- Elastic: Fix folders list scrolling on touch devices (#6706)
13
13
- Elastic: Fix non-working pretty selects in Chrome browser (#6705)
14
14
- Managesieve: Fix bug where global includes were requested for vacation (#6716)
15
+ - Fix bug in HTML parser that could cause missing text fragments when there was no head/body tag (#6713)
15
16
- Fix bug where HTML messages with a xml:namespace tag were not rendered (#6697)
16
17
- Fix TinyMCE download location (#6694)
17
18
- Fix so "Open in new window" consistently displays "external window" interface (#6659)
Original file line number Diff line number Diff line change @@ -562,7 +562,7 @@ public function wash($html)
562
562
if (!$ this ->is_xml && class_exists ('Masterminds\HTML5 ' )) {
563
563
try {
564
564
$ html5 = new Masterminds \HTML5 ();
565
- $ node = $ html5 ->loadHTML ($ html );
565
+ $ node = $ html5 ->loadHTML ($ this -> fix_html5 ( $ html) );
566
566
}
567
567
catch (Exception $ e ) {
568
568
// ignore, fallback to DOMDocument
@@ -778,6 +778,28 @@ public static function fix_broken_lists(&$html)
778
778
}
779
779
}
780
780
781
+ /**
782
+ * Cleanup and workarounds on input to Masterminds/HTML5
783
+ */
784
+ protected function fix_html5 ($ html )
785
+ {
786
+ // HTML5 requires <head> or <body> (#6713)
787
+ // https://github.com/Masterminds/html5-php/issues/166
788
+ if (!preg_match ('/<(head|body)/i ' , $ html )) {
789
+ $ pos = stripos ($ html , '<html ' );
790
+
791
+ if ($ pos === false ) {
792
+ $ html = '<html><body> ' . $ html ;
793
+ }
794
+ else {
795
+ $ pos = strpos ($ html , '> ' , $ pos );
796
+ $ html = substr_replace ($ html , '<body> ' , $ pos , 0 );
797
+ }
798
+ }
799
+
800
+ return $ html ;
801
+ }
802
+
781
803
/**
782
804
* Explode css style value
783
805
*/
Original file line number Diff line number Diff line change @@ -444,4 +444,32 @@ function test_xml_namespace()
444
444
$ this ->assertNotContains ('<?xml:namespace" ' , $ washed );
445
445
$ this ->assertSame ($ washed , '<p></p> ' );
446
446
}
447
+
448
+ /**
449
+ * Test missing main HTML hierarchy tags (#6713)
450
+ */
451
+ function test_missing_tags ()
452
+ {
453
+ $ washer = new rcube_washtml ();
454
+
455
+ $ html = '<head></head>First line<br />Second line ' ;
456
+ $ washed = $ washer ->wash ($ html );
457
+
458
+ $ this ->assertContains ('First line ' , $ washed );
459
+
460
+ $ html = 'First line<br />Second line ' ;
461
+ $ washed = $ washer ->wash ($ html );
462
+
463
+ $ this ->assertContains ('First line ' , $ washed );
464
+
465
+ $ html = '<html>First line<br />Second line</html> ' ;
466
+ $ washed = $ washer ->wash ($ html );
467
+
468
+ $ this ->assertContains ('First line ' , $ washed );
469
+
470
+ $ html = '<html><head></head>First line<br />Second line</html> ' ;
471
+ $ washed = $ washer ->wash ($ html );
472
+
473
+ $ this ->assertContains ('First line ' , $ washed );
474
+ }
447
475
}
You can’t perform that action at this time.
0 commit comments