Page MenuHomePhabricator

0001-WIP-Remove-option-to-tunnelFosteredContent.patch

Authored By
Arlolra
Apr 7 2021, 1:31 PM
Size
8 KB
Subscribers

0001-WIP-Remove-option-to-tunnelFosteredContent.patch

From 77f5b83654b4c0ea21ac2fe2039b0f10f2d416dc Mon Sep 17 00:00:00 2001
From: Arlo Breault <abreault@wikimedia.org>
Date: Tue, 6 Apr 2021 16:55:02 -0400
Subject: [PATCH] [WIP] Remove option to tunnelFosteredContent
This was only useful when porting and we needed to serialize a DOM with
Parsoid's internal metas in fosterable positions. See 3ee85d1
Bug: T279451
Change-Id: I450bdec1af43e256f5b57aa3a786fc4773350a71
---
bin/domdiff.test.php | 1 -
bin/normalize.test.php | 1 -
lib/wt2html/XMLSerializer.js | 22 ---------------
src/Utils/WTUtils.php | 18 +++++--------
src/Wt2Html/HTML5TreeBuilder.php | 7 +++--
src/Wt2Html/PP/Handlers/PrepareDOM.php | 2 +-
src/Wt2Html/XMLSerializer.php | 27 -------------------
tests/phpunit/Parsoid/Html2Wt/DOMDiffTest.php | 1 -
8 files changed, 10 insertions(+), 69 deletions(-)
diff --git a/bin/domdiff.test.php b/bin/domdiff.test.php
index a15cc4e62..edbbd8895 100644
--- a/bin/domdiff.test.php
+++ b/bin/domdiff.test.php
@@ -27,7 +27,6 @@ $opts = [
'env' => $mockEnv,
'keepTmp' => true,
'storeDiffMark' => true,
- 'tunnelFosteredContent' => true,
'quiet' => true
];
ContentUtils::dumpDOM( $body2, 'DIFF-marked DOM', $opts );
diff --git a/bin/normalize.test.php b/bin/normalize.test.php
index e33352edc..064443211 100644
--- a/bin/normalize.test.php
+++ b/bin/normalize.test.php
@@ -26,7 +26,6 @@ $norm->normalize( $body );
$opts = [ 'env' => $mockEnv,
'keepTmp' => true,
'storeDiffMark' => true,
- 'tunnelFosteredContent' => true,
];
ContentUtils::dumpDOM( $body, 'DOM post-normalization', $opts );
print "\n";
diff --git a/lib/wt2html/XMLSerializer.js b/lib/wt2html/XMLSerializer.js
index c767d4227..ca60bd679 100644
--- a/lib/wt2html/XMLSerializer.js
+++ b/lib/wt2html/XMLSerializer.js
@@ -87,28 +87,6 @@ var XMLSerializer = {};
function serializeToString(node, options, accum) {
var child;
- if (options.tunnelFosteredContent && WikitextConstants.HTML.FosterablePosition.has(node.nodeName)) {
- // Tunnel fosterable metas as comments.
- // This is analogous to what is done when treebuilding.
- const ownerDoc = node.ownerDocument;
- const allowedTags = WikitextConstants.HTML.TableContentModels.get(node.nodeName);
- child = node.firstChild;
- while (child) {
- const next = child.nextSibling;
- if (DOMUtils.isText(child)) {
- console.assert(DOMUtils.isIEW(child), 'Only expecting whitespace!');
- } else if (DOMUtils.isElt(child) && !allowedTags.includes(child.nodeName)) {
- console.assert(child.nodeName === 'META', 'Only fosterable metas expected!');
- const comment = WTUtils.fosterCommentData(
- child.getAttribute('typeof'),
- Array.from(child.attributes).map(a => [a.name, a.value]),
- true
- );
- node.replaceChild(ownerDoc.createComment(comment), child);
- }
- child = next;
- }
- }
switch (node.nodeType) {
case ELEMENT_NODE:
child = node.firstChild;
diff --git a/src/Utils/WTUtils.php b/src/Utils/WTUtils.php
index f7af1ac90..073877d4d 100644
--- a/src/Utils/WTUtils.php
+++ b/src/Utils/WTUtils.php
@@ -784,40 +784,34 @@ class WTUtils {
*
* @param string $typeOf
* @param array $attrs
- * @param bool $encode
* @return string
*/
- public static function fosterCommentData( string $typeOf, array $attrs, bool $encode ): string {
- $str = PHPUtils::jsonEncode( [
- '@type' => $typeOf,
+ public static function fosterCommentData( string $typeOf, array $attrs ): string {
+ return PHPUtils::jsonEncode( [
+ '-type' => $typeOf,
'attrs' => $attrs
] );
- if ( $encode ) {
- $str = self::encodeComment( $str );
- }
- return $str;
}
/**
* @param Env $env
* @param DOMNode $node
- * @param bool $decode
* @return ?DOMNode
*/
public static function reinsertFosterableContent(
- Env $env, DOMNode $node, bool $decode
+ Env $env, DOMNode $node
): ?DOMNode {
if ( DOMUtils::isComment( $node ) && preg_match( '/^\{.+\}$/D', $node->nodeValue ) ) {
// Convert serialized meta tags back from comments.
// We use this trick because comments won't be fostered,
// providing more accurate information about where tags are expected
// to be found.
- $data = json_decode( $decode ? self::decodeComment( $node->nodeValue ) : $node->nodeValue );
+ $data = json_decode( $node->nodeValue );
if ( $data === null ) {
// not a valid json attribute, do nothing
return null;
}
- $type = $data->{'@type'} ?? '';
+ $type = $data->{'-type'} ?? '';
if ( preg_match( '/^mw:/', $type ) ) {
$meta = $node->ownerDocument->createElement( 'meta' );
foreach ( $data->attrs as $attr ) {
diff --git a/src/Wt2Html/HTML5TreeBuilder.php b/src/Wt2Html/HTML5TreeBuilder.php
index 2f39a1efc..315b4438a 100644
--- a/src/Wt2Html/HTML5TreeBuilder.php
+++ b/src/Wt2Html/HTML5TreeBuilder.php
@@ -309,7 +309,7 @@ class HTML5TreeBuilder extends PipelineStage {
new KV( 'data-stag', "{$tName}:{$dataAttribs->tmp->tagId}" )
], Utils::clone( $dataAttribs ) );
$this->dispatcher->comment(
- WTUtils::fosterCommentData( 'mw:shadow', $this->kvArrToFoster( $attrs ), false ),
+ WTUtils::fosterCommentData( 'mw:shadow', $this->kvArrToFoster( $attrs ) ),
0, 0
);
}
@@ -347,8 +347,7 @@ class HTML5TreeBuilder extends PipelineStage {
$this->dispatcher->comment(
WTUtils::fosterCommentData(
$token->getAttribute( 'typeof' ) ?? '',
- $this->kvArrToFoster( $attribs ),
- false
+ $this->kvArrToFoster( $attribs )
), 0, 0
);
$wasInserted = true;
@@ -382,7 +381,7 @@ class HTML5TreeBuilder extends PipelineStage {
]
);
$this->dispatcher->comment(
- WTUtils::fosterCommentData( 'mw:shadow', $this->kvArrToFoster( $attrs ), false ),
+ WTUtils::fosterCommentData( 'mw:shadow', $this->kvArrToFoster( $attrs ) ),
0, 0
);
}
diff --git a/src/Wt2Html/PP/Handlers/PrepareDOM.php b/src/Wt2Html/PP/Handlers/PrepareDOM.php
index 30a77b5c0..30a990192 100644
--- a/src/Wt2Html/PP/Handlers/PrepareDOM.php
+++ b/src/Wt2Html/PP/Handlers/PrepareDOM.php
@@ -47,7 +47,7 @@ class PrepareDOM {
}
return true;
}
- $meta = WTUtils::reinsertFosterableContent( $env, $node, false );
+ $meta = WTUtils::reinsertFosterableContent( $env, $node );
return $meta ?? true;
}
}
diff --git a/src/Wt2Html/XMLSerializer.php b/src/Wt2Html/XMLSerializer.php
index 6e3b32b7f..d35de9ae4 100644
--- a/src/Wt2Html/XMLSerializer.php
+++ b/src/Wt2Html/XMLSerializer.php
@@ -77,33 +77,6 @@ class XMLSerializer {
*/
private static function serializeToString( DOMNode $node, array $options, callable $accum ): void {
$child = null;
- if ( !empty( $options['tunnelFosteredContent'] ) &&
- isset( WikitextConstants::$HTML['FosterablePosition'][$node->nodeName] )
- ) {
- // Tunnel fosterable metas as comments.
- // This is analogous to what is done when treebuilding.
- $ownerDoc = $node->ownerDocument;
- $allowedTags = WikitextConstants::$HTML['TableContentModels'][$node->nodeName];
- $child = $node->firstChild;
- while ( $child ) {
- $next = $child->nextSibling;
- if ( DOMUtils::isText( $child ) ) {
- Assert::invariant( DOMUtils::isIEW( $child ), 'Only expecting whitespace!' );
- } elseif (
- $child instanceof DOMElement &&
- !in_array( $child->nodeName, $allowedTags, true )
- ) {
- Assert::invariant( $child->nodeName === 'meta', 'Only fosterable metas expected!' );
- $as = [];
- foreach ( DOMCompat::attributes( $child ) as $attr ) {
- $as[] = [ $attr->name, $attr->value ];
- }
- $comment = WTUtils::fosterCommentData( $child->getAttribute( 'typeof' ), $as, true );
- $node->replaceChild( $ownerDoc->createComment( $comment ), $child );
- }
- $child = $next;
- }
- }
switch ( $node->nodeType ) {
case XML_ELEMENT_NODE:
DOMUtils::assertElt( $node );
diff --git a/tests/phpunit/Parsoid/Html2Wt/DOMDiffTest.php b/tests/phpunit/Parsoid/Html2Wt/DOMDiffTest.php
index d50d4b057..ac9239476 100644
--- a/tests/phpunit/Parsoid/Html2Wt/DOMDiffTest.php
+++ b/tests/phpunit/Parsoid/Html2Wt/DOMDiffTest.php
@@ -45,7 +45,6 @@ class DOMDiffTest extends TestCase {
'env' => $mockEnv,
'keepTmp' => true,
'storeDiffMark' => true,
- 'tunnelFosteredContent' => true,
'quiet' => true
];
DOMDataUtils::visitAndStoreDataAttribs( $body, $opts );
--
2.31.1

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8975731

Event Timeline

Couldn't most of the code that removes the tunneling be a regular gerrit patch and the @type -> -type change be part of this private security patch? Or is the intention to hide the two together?

The intention was to obscure the security related change, yes