diff --git a/src/Dom/Document.php b/src/Dom/Document.php index be155d336..34ba9651e 100644 --- a/src/Dom/Document.php +++ b/src/Dom/Document.php @@ -202,6 +202,7 @@ public function __construct($version = '', $encoding = null) Filter\DocumentEncoding::class, Filter\HttpEquivCharset::class, Filter\LibxmlCompatibility::class, + Filter\ProtectEsiTags::class, ] ); } diff --git a/src/Dom/Document/Filter/ProtectEsiTags.php b/src/Dom/Document/Filter/ProtectEsiTags.php new file mode 100644 index 000000000..6071429cf --- /dev/null +++ b/src/Dom/Document/Filter/ProtectEsiTags.php @@ -0,0 +1,61 @@ +]*?)(?>\s*(?(?!)#'; + + $html = preg_replace($selfClosingregex, '<$1$2>', $html); + $html = preg_replace('/(#i'; + + $html = preg_replace('/(<\/?)esi-/', '$1esi:', $html); + $html = preg_replace('/(', $html); + + return $html; + } +} diff --git a/tests/Dom/DocumentTest.php b/tests/Dom/DocumentTest.php index e9d0eb454..d5391fc45 100644 --- a/tests/Dom/DocumentTest.php +++ b/tests/Dom/DocumentTest.php @@ -467,6 +467,29 @@ public function dataDomDocument() '' . $head . '', '' . $head . '', ], + 'preserve Varnish esi tags' => [ + 'utf-8', + '' + . ' ' + . ' ' + . ' ' + . ' ' + . ' ' + . ' ' + . ' ' + . ' ' + . '', + '' . $head . '' + . ' ' + . ' ' + . ' ' + . ' ' + . ' ' + . ' ' + . ' ' + . ' ' + . '', + ] ]; }