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
This commit is contained in:
Ed Sanders 2020-08-07 18:32:45 +01:00 committed by Bartosz Dziewoński
parent c26ca107db
commit 7b2448d2f0
2 changed files with 4 additions and 1 deletions

View file

@ -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(),

View file

@ -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 );
}