From 7b2448d2f051995249d9cd3d5811bde44a685669 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 7 Aug 2020 18:32:45 +0100 Subject: [PATCH] Use DOMCompat::getOuterHTML instead of doc->saveHTML() The latter results in lots of extra HTML entity encoding. The former is built by the Parsing team and appears to result in no unexpected changes elsewhere in the document. As Parsoid's selser relies on HTML fragments being byte-for-byte equal, these changes were resulting in wikitext normalisations in untouched parts of the document ("dirty diffs"). Bug: T259855 Change-Id: Ib3cb605911e690ec3e8c2f9df25fd1a2e2849d7e --- includes/ApiDiscussionToolsEdit.php | 3 ++- tests/phpunit/CommentModifierTest.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/ApiDiscussionToolsEdit.php b/includes/ApiDiscussionToolsEdit.php index 770e7139d..8cf2c4d8c 100644 --- a/includes/ApiDiscussionToolsEdit.php +++ b/includes/ApiDiscussionToolsEdit.php @@ -9,6 +9,7 @@ use DerivativeRequest; use DOMElement; use Title; use Wikimedia\ParamValidator\ParamValidator; +use Wikimedia\Parsoid\Utils\DOMCompat; use Wikimedia\Parsoid\Utils\DOMUtils; class ApiDiscussionToolsEdit extends ApiBase { @@ -87,7 +88,7 @@ class ApiDiscussionToolsEdit extends ApiBase { 'page' => $params['page'], 'token' => $params['token'], 'oldid' => $oldid, - 'html' => $doc->saveHtml(), + 'html' => DOMCompat::getOuterHTML( $doc->documentElement ), 'summary' => $summary, 'baserevid' => $revision->getId(), 'starttimestamp' => wfTimestampNow(), diff --git a/tests/phpunit/CommentModifierTest.php b/tests/phpunit/CommentModifierTest.php index 977cf8680..99f50d519 100644 --- a/tests/phpunit/CommentModifierTest.php +++ b/tests/phpunit/CommentModifierTest.php @@ -46,6 +46,7 @@ class CommentModifierTest extends CommentTestCase { // Uncomment this to write updated content to the "modified HTML" files: // self::overwriteHtmlFile( $expectedPath, $doc, $origPath ); + // saveHtml is not dirty-diff safe, but for testing it is probably faster than DOMCompat::getOuterHTML self::assertEquals( $expectedDoc->saveHtml(), $doc->saveHtml(), $name ); // removeAddedListItem is not implemented on the server @@ -89,6 +90,7 @@ class CommentModifierTest extends CommentTestCase { // Uncomment this to write updated content to the "reply HTML" files: // self::overwriteHtmlFile( $expectedPath, $doc, $origPath ); + // saveHtml is not dirty-diff safe, but for testing it is probably faster than DOMCompat::getOuterHTML self::assertEquals( $expectedDoc->saveHtml(), $doc->saveHtml(), $name ); }