Fix incorrect escaping of nested <em>, <strong>, <q>, <ruby>, and <bdo>
authorC. Scott Ananian <cscott@cscott.net>
Wed, 10 Jul 2013 17:03:21 +0000 (13:03 -0400)
committerC. Scott Ananian <cscott@cscott.net>
Wed, 10 Jul 2013 17:07:45 +0000 (13:07 -0400)
The parser, when given "<em>X<em>Y</em>Z</em>" was emitting
"<p><em>X&lt;em&gt;Y</em>Z&lt;/em&gt;</p>".  This is the same as bug
41545, but with a different set of tags.

Note that the HTML spec
(http://www.w3.org/TR/html5/text-level-semantics.html) gives an
explicit meaning for nested <em>, <strong>, <q>, <ruby>, and <bdo>.

There are other nestable tags (<b>, <i>, <s>, <u>, <cite>, <dfn>,
<abbr>, <time>, <code>, <mark>, <rt>, <rp>, <bdi>) which I've chosen
not to fix in this commit since the spec allows but does not give
semantics for them.  A wikipedian authoring content with these nested
tags is probably making an error; the escaped content will make this
obvious.

Bug: 51081
Change-Id: Ia940ac54e9527bba7fee75d3bd91babee2f91c57

includes/Sanitizer.php
tests/parser/parserTests.txt

index 7400a5a..fa883fc 100644 (file)
@@ -397,7 +397,7 @@ class Sanitizer {
                        $htmlnest = array( # Tags that can be nested--??
                                'table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul',
                                'li', 'dl', 'dt', 'dd', 'font', 'big', 'small', 'sub', 'sup', 'span',
-                               'var', 'kbd', 'samp'
+                               'var', 'kbd', 'samp', 'em', 'strong', 'q', 'ruby', 'bdo'
                        );
                        $tabletags = array( # Can only appear inside table, we will close them
                                'td', 'th', 'tr',
index 478b348..337342a 100644 (file)
@@ -1106,7 +1106,7 @@ b
 !! end
 
 ###
-### paragraph wraping tests
+### paragraph wrapping tests
 ###
 !! test
 No block tags
@@ -9503,6 +9503,81 @@ I always thought &xacute; was a cute letter.
 !! end
 
 
+###
+### Nesting tests (see bug 41545, 50604, 51081)
+###
+
+# This test case is fixed in Parsoid by domino 1.0.12. (bug 50604)
+# Note that html2wt is considerably more difficult if we use <b> in
+# the test case, instead of <big>
+!! test
+Ensure that HTML adoption agency algorithm is properly implemented.
+!! input
+<big>X<big>Y</big>Z</big>
+!! result
+<p><big>X<big>Y</big>Z</big>
+</p>
+!! end
+
+# This was bug 41545 in the PHP parser.
+!! test
+Nesting of <kbd>
+!! input
+<kbd>X<kbd>Y</kbd>Z</kbd>
+!! result
+<p><kbd>X<kbd>Y</kbd>Z</kbd>
+</p>
+!! end
+
+# The following cases were bug 51081 in the PHP parser.
+# Note that there are some other nestable tags (b, i, etc) which are
+# not covered; see bug 51081 for discussion.
+!! test
+Nesting of <em>
+!! input
+<em>X<em>Y</em>Z</em>
+!! result
+<p><em>X<em>Y</em>Z</em>
+</p>
+!! end
+
+!! test
+Nesting of <strong>
+!! input
+<strong>X<strong>Y</strong>Z</strong>
+!! result
+<p><strong>X<strong>Y</strong>Z</strong>
+</p>
+!! end
+
+!! test
+Nesting of <q>
+!! input
+<q>X<q>Y</q>Z</q>
+!! result
+<p><q>X<q>Y</q>Z</q>
+</p>
+!! end
+
+!! test
+Nesting of <ruby>
+!! input
+<ruby>X<ruby>Y</ruby>Z</ruby>
+!! result
+<p><ruby>X<ruby>Y</ruby>Z</ruby>
+</p>
+!! end
+
+!! test
+Nesting of <bdo>
+!! input
+<bdo>X<bdo>Y</bdo>Z</bdo>
+!! result
+<p><bdo>X<bdo>Y</bdo>Z</bdo>
+</p>
+!! end
+
+
 ###
 ### Media links
 ###
@@ -16158,31 +16233,6 @@ parsoid=html2wt
 </ul>
 !! end
 
-# This test case is fixed by domino 1.0.12.
-# Note that html2wt is considerably more difficult if we use <b> in
-# the test case, instead of <big>
-!! test
-Ensure that HTML adoption agency algorithm is properly implemented.
-!! options
-!! input
-<big>X<big>Y</big>Z</big>
-!! result
-<p><big>X<big>Y</big>Z</big>
-</p>
-!! end
-
-# The parsoid team believes the below behavior of the PHP parser to be
-# a bug.
-!! test
-Document PHP parser behavior for HTML adoption agency test case.
-!! options
-php
-!! input
-<em>X<em>Y</em>Z</em>
-!! result
-<p><em>X&lt;em&gt;Y</em>Z&lt;/em&gt;
-</p>
-!! end
 
 TODO:
 more images