jenkins-bot has submitted this change and it was merged.

Change subject: Patch HTML5 to foster style,base,link,script from tables
......................................................................


Patch HTML5 to foster style,base,link,script from tables

* HTML5 library we use has a bug where it assumes that
  <style>, <base>, <meta>, <link>, <script> tags only show up
  in the html header.  As a result, it doesn't check if they
  are fosterable out of a table if they show up in fosterable
  positions.

* Patched the library to handle <style>, <base>, <link>, <script>
  tags when in a table context.

* Left the <meta> bug untouched since Parsoid currently exploits
  this bug for detecting unclosed start/end tags and a few other
  things.  Once Parsoid is fixed to deal with this without relying
  on the bug, we can patch this last piece of the bug as well.

* No change in parser test results.

* The following snippet is correctly handled where it wasn't before.
  The category link is fostered out (which also means that this
  wont RT correctly right now).

  "<table>[[Category:foo]]<tr><td>foo</td></tr></table>"

* Bug detected this bug report on parsoid.wmflabs.org
* /mnt/bugs/2013-06-07T12:54:55.516Z-Palais_(rivi%C3%A8re)

Change-Id: Ia30f6cf02cba7816dc7e92e974be6bfe63462d37
---
M js/lib/html5/parser/in_head_phase.js
1 file changed, 40 insertions(+), 15 deletions(-)

Approvals:
  GWicke: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/js/lib/html5/parser/in_head_phase.js 
b/js/lib/html5/parser/in_head_phase.js
index 4a85cf4..62c2fe2 100644
--- a/js/lib/html5/parser/in_head_phase.js
+++ b/js/lib/html5/parser/in_head_phase.js
@@ -72,12 +72,19 @@
 }
 
 p.prototype.startTagStyle = function(name, attributes) {
-       if(this.tree.head_pointer && this.parser.phaseName == 'inHead') {
-               var element = this.tree.createElement(name, attributes);
-               this.appendToHead(element);
-               this.tree.open_elements.push(element);
+       if (this.tree.insert_from_table) {
+               // SSS FIXME: html5 library assumes that the style tag
+               // only shows up in head and doesn't check if it needs
+               // to be fostered.  So, we are patching the html5 lib.
+               this.tree.insert_element_from_table(name, attributes);
        } else {
-               this.tree.insert_element(name, attributes);
+               if(this.tree.head_pointer && this.parser.phaseName == 'inHead') 
{
+                       var element = this.tree.createElement(name, attributes);
+                       this.appendToHead(element);
+                       this.tree.open_elements.push(element);
+               } else {
+                       this.tree.insert_element(name, attributes);
+               }
        }
        this.parser.tokenizer.content_model = HTML5.Models.CDATA;
 }
@@ -95,24 +102,42 @@
 }
 
 p.prototype.startTagScript = function(name, attributes) {
-       // XXX Inner HTML case may be wrong
-       var element = this.tree.createElement(name, attributes);
-       //element.flags.push('parser-inserted');
-       if(this.tree.head_pointer && this.parser.phaseName == 'inHead') {
-               this.appendToHead(element);
+       if (this.tree.insert_from_table) {
+               // SSS FIXME: html5 library assumes that the style tag
+               // only shows up in head and doesn't check if it needs
+               // to be fostered.  So, we are patching the html5 lib.
+               this.tree.insert_element_from_table(name, attributes);
        } else {
-               this.tree.open_elements.last().appendChild(element);
+               // XXX Inner HTML case may be wrong
+               var element = this.tree.createElement(name, attributes);
+               //element.flags.push('parser-inserted');
+               if(this.tree.head_pointer && this.parser.phaseName == 'inHead') 
{
+                       this.appendToHead(element);
+               } else {
+                       this.tree.open_elements.last().appendChild(element);
+               }
        }
        this.tree.open_elements.push(element);
        this.parser.tokenizer.content_model = HTML5.Models.SCRIPT_CDATA;
 }
 
 p.prototype.startTagBaseLinkMeta = function(name, attributes) {
-       var element = this.tree.createElement(name, attributes);
-       if(this.tree.head_pointer && this.parser.phaseName == 'inHead') {
-               this.appendToHead(element);
+       // SSS FIXME: html5 library assumes that base,link,meta
+       // tags only show up in head and doesn't check if they need
+       // to be fostered.  So, we are patching the html5 lib.
+       //
+       // Right now, Parsoid exploits this bug for meta tags.
+       // So, till Parsoid is fixed to not rely on this bug,
+       // we'll continue to not to foster meta tags out of tables.
+       if (name !== 'meta' && this.tree.insert_from_table) {
+               this.tree.insert_element_from_table(name, attributes);
        } else {
-               this.tree.open_elements.last().appendChild(element);
+               var element = this.tree.createElement(name, attributes);
+               if(this.tree.head_pointer && this.parser.phaseName == 'inHead') 
{
+                       this.appendToHead(element);
+               } else {
+                       this.tree.open_elements.last().appendChild(element);
+               }
        }
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/67553
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia30f6cf02cba7816dc7e92e974be6bfe63462d37
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to