Arlolra has uploaded a new change for review.
https://gerrit.wikimedia.org/r/260535
Change subject: Use domino internal methods for setting attributes while parsing
......................................................................
Use domino internal methods for setting attributes while parsing
* This avoid the checks that aren't meant to be applied.
* Fixes crashers on:
dewiki/2._Fußball-Bundesliga_2015%2F16?oldid=146541308
enwiki/WWL_World_Trios_Championship?oldid=678143660
Bug: T114225, T121611
Change-Id: I5508b266dd676297e4c9062d8963ab7b5bee3b8b
---
M lib/wt2html/HTML5TreeBuilder.js
1 file changed, 35 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/35/260535/1
diff --git a/lib/wt2html/HTML5TreeBuilder.js b/lib/wt2html/HTML5TreeBuilder.js
index 9b0ca3d..0bc3de2 100644
--- a/lib/wt2html/HTML5TreeBuilder.js
+++ b/lib/wt2html/HTML5TreeBuilder.js
@@ -7,7 +7,7 @@
var events = require('events');
var util = require('util');
-var HTML5 = require('html5');
+var DOMTreeBuilder = require('html5').DOMTreeBuilder;
var domino = require('domino');
var defines = require('./parser.defines.js');
var Util = require('../utils/Util.js').Util;
@@ -56,6 +56,39 @@
// HTML5 tokenizer stubs
TreeBuilder.prototype.setState = function(state) {};
+// DOMTB is a terrible name but we've already stolen TreeBuilder for what is
+// actually the tokenizer in the html5 library parlance.
+var DOMTB = function() {
+ DOMTreeBuilder.apply(this, arguments);
+};
+
+util.inherits(DOMTB, DOMTreeBuilder);
+
+// Overwrite `createElement` and `addAttributesToElement` with modified
+// versions of the originals to call domino internal methods that avoid
+// error checking when setting attributes. These checks aren't normally
+// applied when parsing.
+DOMTB.prototype.createElement = function(namespaceURI, localName, attributes) {
+ var element = this.document.createElementNS(namespaceURI, localName);
+ if (attributes) {
+ for (var i = 0; i < attributes.length; i++) {
+ element._setAttributeNS(attributes[i].namespaceURI ||
null,
+ attributes[i].nodeName,
attributes[i].nodeValue);
+ }
+ }
+ return element;
+};
+
+DOMTB.prototype.addAttributesToElement = function(element, attributes) {
+ for (var i = 0; i < attributes.length; i++) {
+ if (!element.getAttributeNS(attributes[i].namespaceURI || null,
+ attributes[i].nodeName)) {
+ element._setAttributeNS(attributes[i].namespaceURI ||
null,
+ attributes[i].nodeName,
attributes[i].nodeValue);
+ }
+ }
+};
+
TreeBuilder.prototype.resetState = function() {
// Reset vars
this.tagId = 1; // Assigned to start/self-closing tags
@@ -83,7 +116,7 @@
if (!this._treeBuilder) {
// Set up a new tree builder
- this._treeBuilder = new HTML5.DOMTreeBuilder(domino);
+ this._treeBuilder = new DOMTB(domino);
this.addListener('token',
this._treeBuilder.processToken.bind(this._treeBuilder));
}
--
To view, visit https://gerrit.wikimedia.org/r/260535
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5508b266dd676297e4c9062d8963ab7b5bee3b8b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits