Prevent unexpected }- in converter output
authorLiangent <liangent@gmail.com>
Thu, 23 Apr 2015 06:33:48 +0000 (06:33 +0000)
committerC. Scott Ananian <cananian@wikimedia.org>
Wed, 25 Jan 2017 17:38:08 +0000 (17:38 +0000)
Previously for input -{<span title="-{X}-">X</span>}-, the converter
sees -{<span title="-&#123;X}-">A</span>}-, so <span title="-&#123;X
becomes the content in the first block, and a stray }- is left to output.

Now, the converter sees -{<span title="-&#123;X&#125;-">A</span>}- with
this change. In further processing, the span tag may be parsed and have
its title attrib converted. For cases where the content is not processed
further (eg. "R" = raw flag), "-{X}-" is left as is in the attrib, which
is not so ideal, but at least it's better than the original extra }-
outside the whole tag.

Change-Id: Idbaaf53f914f362e5b8cc9fad02a524f8d591bb7

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

index 6779189..42b166d 100644 (file)
@@ -1119,6 +1119,7 @@ class Sanitizer {
                        '>'    => '&gt;',   // we've received invalid input
                        '"'    => '&quot;', // which should have been escaped.
                        '{'    => '&#123;',
+                       '}'    => '&#125;', // prevent unpaired language conversion syntax
                        '['    => '&#91;',
                        "''"   => '&#39;&#39;',
                        'ISBN' => '&#73;SBN',
index ed09203..aa79208 100644 (file)
@@ -16083,7 +16083,7 @@ div with braces in attribute value
 !! wikitext
 <div title="{}">Foo</div>
 !! html/php
-<div title="&#123;}">Foo</div>
+<div title="&#123;&#125;">Foo</div>
 
 !! html/parsoid
 <div title="{}">Foo</div>
@@ -20625,6 +20625,28 @@ Nested: -{zh-hans:Hi -{zh-cn:China;zh-sg:Singapore;}-;zh-hant:Hello -{zh-tw:Taiw
 # Since Parsoid is starting to emit canonical wikitext for links,
 # [http://example.com http://example.com] will not RT back to that
 # form anymore.
+!! test
+HTML markups with conversion syntax in attribs, nested in other conversion blocks
+!! options
+language=zh variant=zh-cn
+!! wikitext
+-{zh;zh-hans;zh-hant|<span title="-{X}-">A</span>}-
+!! html
+<p><span title="X">A</span>
+</p>
+!! end
+
+!! test
+HTML markups with conversion syntax in attribs, nested in other conversion blocks (not working yet)
+!! options
+language=zh variant=zh-cn disabled
+!! wikitext
+-{<span title="-{X}-">A</span>}-
+!! html
+<p><span title="X">A</span>
+</p>
+!! end
+
 !! test
 Proper conversion of text in external links
 !! options