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

Change subject: T107474: Fix <nowiki> escape of | in image captions
......................................................................


T107474: Fix <nowiki> escape of | in image captions

Change-Id: I33e4dacb0f55b19690db80a52a7af17560814757
---
M lib/ext.core.LinkHandler.js
M tests/parserTests-blacklist.js
M tests/parserTests.txt
3 files changed, 5 insertions(+), 6 deletions(-)

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



diff --git a/lib/ext.core.LinkHandler.js b/lib/ext.core.LinkHandler.js
index 4fc51f5..35d362d 100644
--- a/lib/ext.core.LinkHandler.js
+++ b/lib/ext.core.LinkHandler.js
@@ -877,6 +877,10 @@
                        resultStr += nextResult;
                } else if (currentToken.constructor !== EndTagTk) {
                        // This is actually a token
+                       if (currentToken.name === 'span' && 
currentToken.getAttribute('typeof') === 'mw:Nowiki') {
+                               // if this is a nowiki, we must be in a caption
+                               return null;
+                       }
                        if (currentToken.name === 'a') {
                                if (optInfo === undefined) {
                                        optInfo = getOptionInfo(prefix + 
resultStr, env);
diff --git a/tests/parserTests-blacklist.js b/tests/parserTests-blacklist.js
index 5802270..7121684 100644
--- a/tests/parserTests-blacklist.js
+++ b/tests/parserTests-blacklist.js
@@ -143,7 +143,6 @@
 add("wt2html", "Image with link parameter, wgNoFollowDomainExceptions", "<p 
data-parsoid='{\"dsr\":[0,45,0,0]}'><span class=\"mw-default-size\" 
typeof=\"mw:Image\" 
data-parsoid='{\"optList\":[{\"ck\":\"link\",\"ak\":\"link=http://example.com/\"}],\"dsr\":[0,45,null,null]}'><a
 href=\"http://example.com/\"; data-parsoid=\"{}\"><img 
resource=\"./File:Foobar.jpg\" src=\"//example.com/images/3/3a/Foobar.jpg\" 
data-file-width=\"1941\" data-file-height=\"220\" data-file-type=\"bitmap\" 
height=\"220\" width=\"1941\" 
data-parsoid='{\"a\":{\"resource\":\"./File:Foobar.jpg\",\"height\":\"220\",\"width\":\"1941\"},\"sa\":{\"resource\":\"Image:foobar.jpg\"}}'/></a></span></p>");
 add("wt2html", "Image with link parameter, wgExternalLinkTarget, unnamed 
parameter", "<p data-parsoid='{\"dsr\":[0,51,0,0]}'><span 
class=\"mw-default-size\" typeof=\"mw:Image\" 
data-parsoid='{\"optList\":[{\"ck\":\"link\",\"ak\":\"link=http://example.com/\"},{\"ck\":\"caption\",\"ak\":\"Title\"}],\"dsr\":[0,51,null,null]}'
 data-mw='{\"caption\":\"Title\"}'><a href=\"http://example.com/\"; 
data-parsoid=\"{}\"><img resource=\"./File:Foobar.jpg\" 
src=\"//example.com/images/3/3a/Foobar.jpg\" data-file-width=\"1941\" 
data-file-height=\"220\" data-file-type=\"bitmap\" height=\"220\" 
width=\"1941\" 
data-parsoid='{\"a\":{\"resource\":\"./File:Foobar.jpg\",\"height\":\"220\",\"width\":\"1941\"},\"sa\":{\"resource\":\"Image:foobar.jpg\"}}'/></a></span></p>");
 add("wt2html", "SVG thumbnails with invalid language code", "<figure 
class=\"mw-default-size\" typeof=\"mw:Image/Thumb\" 
data-parsoid='{\"optList\":[{\"ck\":\"thumbnail\",\"ak\":\"thumb\"},{\"ck\":\"caption\",\"ak\":\"caption\"},{\"ck\":\"lang\",\"ak\":\"lang=invalid.language.code\"}],\"dsr\":[0,60,2,2]}'><a
 href=\"./File:Foobar.svg\" 
data-parsoid='{\"a\":{\"href\":\"./File:Foobar.svg\"},\"sa\":{},\"dsr\":[2,null,null,null]}'><img
 resource=\"./File:Foobar.svg\" 
src=\"//example.com/images/thumb/f/ff/Foobar.svg/220px-Foobar.svg\" 
lang=\"invalid.language.code\" data-file-width=\"240\" data-file-height=\"180\" 
data-file-type=\"drawing\" height=\"165\" width=\"220\" 
data-parsoid='{\"a\":{\"resource\":\"./File:Foobar.svg\",\"lang\":\"invalid.language.code\",\"height\":\"165\",\"width\":\"220\"},\"sa\":{\"resource\":\"File:Foobar.svg\",\"lang\":\"lang=invalid.language.code\"}}'/></a><figcaption
 data-parsoid='{\"dsr\":[null,58,null,null]}'>caption</figcaption></figure>");
-add("wt2html", "T107474: Frameless image caption with <nowiki>", "<p 
data-parsoid='{\"dsr\":[0,77,0,0]}'><span class=\"mw-default-size\" 
typeof=\"mw:Image mw:Placeholder\" 
data-parsoid='{\"optList\":[{\"ck\":\"bogus\",\"ak\":\"text with a 
[[MeatBall:Link\"},{\"ck\":\"caption\",\"ak\":\"link]] in 
it\"}],\"uneditable\":true,\"dsr\":[0,77,null,null]}' 
data-mw='{\"caption\":\"link]] in it\"}'><a href=\"./File:Foobar.jpg\" 
data-parsoid='{\"a\":{\"href\":\"./File:Foobar.jpg\"},\"sa\":{}}'><img 
resource=\"./File:Foobar.jpg\" src=\"//example.com/images/3/3a/Foobar.jpg\" 
data-file-width=\"1941\" data-file-height=\"220\" data-file-type=\"bitmap\" 
height=\"220\" width=\"1941\" 
data-parsoid='{\"a\":{\"resource\":\"./File:Foobar.jpg\",\"height\":\"220\",\"width\":\"1941\"},\"sa\":{\"resource\":\"File:Foobar.jpg\"}}'/></a></span></p>");
 add("wt2html", "BUG 561: {{/Subpage}}", "<p 
data-parsoid='{\"dsr\":[0,12,0,0]}'><span typeof=\"mw:Transclusion 
mw:Placeholder\" about=\"#mwt1\" id=\"mwt1\" 
data-parsoid='{\"dsr\":[0,12,null,null],\"pi\":[[]]}' 
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"/Subpage\",\"href\":\"./Template:/Subpage\"},\"params\":{},\"i\":0}}]}'>Warning:
 Page/template fetching disabled, and no cache for 
Template:/Subpage</span></p>");
 add("wt2html", "Simple category", "<link rel=\"mw:PageProp/Category\" 
href=\"./Category:MediaWiki_User's_Guide\" 
data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Category:MediaWiki_User&#39;s_Guide\"},\"sa\":{\"href\":\"Category:MediaWiki
 User&#39;s Guide\"},\"dsr\":[0,35,null,null]}'/>");
 add("wt2html", "PAGESINCATEGORY invalid title fatal (r33546 fix)", "<p 
about=\"#mwt1\" typeof=\"mw:Transclusion\" 
data-parsoid='{\"dsr\":[0,27,0,0],\"pi\":[[]]}' 
data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"PAGESINCATEGORY:&lt;bogus>\",\"function\":\"pagesincategory\"},\"params\":{},\"i\":0}}]}'>Parser
 function implementation for pf_pagesincategory missing in Parsoid.</p>");
@@ -369,7 +368,6 @@
 add("wt2wt", "Templates: HTML Tables: 5. Proper fostering of categories from 
inside", "[[Category:foo1]]<table><tr><td>foo</td></tr></table>\n<!--Two 
categories (Bug 
50330)-->\n[[Category:bar1]][[Category:bar2]]<table><tr><td>foo</td></tr></table>");
 add("wt2wt", "Allow empty links in image captions (Bug 60753)", 
"[[File:Foobar.jpg|thumb|Caption 
[[Link1]]\n<nowiki>[[]]</nowiki>\n[[Link2]]\n]]");
 add("wt2wt", "Image with multiple widths -- use last", 
"[[File:Foobar.jpg|300px|caption]]\n");
-add("wt2wt", "T107474: Frameless image caption with <nowiki>", 
"[[File:Foobar.jpg|<nowiki>link]] in it</nowiki>]]\n");
 add("wt2wt", "Render invalid page names as plain text (bug 51090)", 
"<nowiki>[[./../foo|bar]]</nowiki>\n<nowiki>[[foo�|bar]]</nowiki>\n<nowiki>[[foo/.|bar]]</nowiki>\n<nowiki>[[foo/..|bar]]</nowiki>\n<nowiki>[[foo~~~bar]]</nowiki>\n<nowiki>[[foo>bar]]</nowiki>\n[[foo[bar]]\n<nowiki>[[.]]</nowiki>\n<nowiki>[[..]]</nowiki>\n<nowiki>[[foo././bar]]</nowiki>\n\n[[{{echo|./../foo}}|bar]]\n[[{{echo|foo/.}}|bar]]\n[[{{echo|foo/..}}|bar]]\n[[{{echo|foo~~~~bar}}]]\n[[{{echo|foo>bar}}]]\n[[{{echo|foo././bar}}]]\n[[{{echo|foo{bar}}]]\n[[{{echo|foo}bar}}]]\n[[{{echo|foo[bar}}]]\n[[{{echo|foo]bar}}]]\n[[{{echo|foo<bar}}]]\n");
 add("wt2wt", "Handling of sections up to level 6 and beyond", "= Level 1 
Heading=\n== Level 2 Heading==\n=== Level 3 Heading===\n==== Level 4 
Heading====\n===== Level 5 Heading=====\n====== Level 6 
Heading======\n======<nowiki>= Level 7 
Heading=</nowiki>======\n======<nowiki>== Level 8 
Heading==</nowiki>======\n======<nowiki>=== Level 9 
Heading===</nowiki>======\n======<nowiki>==== Level 10 
Heading====</nowiki>======\n");
 add("wt2wt", "div with single-quoted attribute", "<div id=\"rock\">HTML 
rocks</div>");
@@ -546,7 +544,6 @@
 add("html2html", "Link to image page- image page normally doesn't exists, 
hence edit link\nAdd test with existing image page\n#<p><a 
href=\"/wiki/File:Test\" title=\"Image:Test\">Image:test</a>", "<p 
data-parsoid='{\"dsr\":[0,61,0,0]}'>[/index.php?title=File:Test&amp;action=edit&amp;redlink=1
 Image:test]</p>\n");
 add("html2html", "bug 18784  Link to non-existent image page with caption 
should use caption as link text", "<p 
data-parsoid='{\"dsr\":[0,58,0,0]}'>[/index.php?title=File:Test&amp;action=edit&amp;redlink=1
 caption]</p>\n");
 add("html2html", "SVG thumbnails with invalid language code", "<figure 
class=\"mw-default-size\" typeof=\"mw:Image/Thumb\" 
data-parsoid='{\"optList\":[{\"ck\":\"thumbnail\",\"ak\":\"thumb\"},{\"ck\":\"lang\",\"ak\":\"lang=invalid.language.code\"}],\"dsr\":[0,52,2,2]}'><a
 href=\"./File:Foobar.svg\" 
data-parsoid='{\"a\":{\"href\":\"./File:Foobar.svg\"},\"sa\":{},\"dsr\":[2,50,null,null]}'><img
 resource=\"./File:Foobar.svg\" 
src=\"//example.com/images/thumb/f/ff/Foobar.svg/220px-Foobar.svg\" 
lang=\"invalid.language.code\" data-file-width=\"240\" data-file-height=\"180\" 
data-file-type=\"drawing\" height=\"165\" width=\"220\" 
data-parsoid='{\"a\":{\"resource\":\"./File:Foobar.svg\",\"lang\":\"invalid.language.code\",\"height\":\"165\",\"width\":\"220\"},\"sa\":{\"resource\":\"File:Foobar.svg\",\"lang\":\"lang=invalid.language.code\"}}'/></a></figure>\n");
-add("html2html", "T107474: Frameless image caption with <nowiki>", "<p 
data-parsoid='{\"dsr\":[0,77,0,0]}'><span class=\"mw-default-size\" 
typeof=\"mw:Image mw:Placeholder\" 
data-parsoid='{\"optList\":[{\"ck\":\"bogus\",\"ak\":\"text with a 
[[MeatBall:Link\"},{\"ck\":\"caption\",\"ak\":\"link]] in 
it\"}],\"uneditable\":true,\"dsr\":[0,77,null,null]}' 
data-mw='{\"caption\":\"link]] in it\"}'><a href=\"./File:Foobar.jpg\" 
data-parsoid='{\"a\":{\"href\":\"./File:Foobar.jpg\"},\"sa\":{}}'><img 
resource=\"./File:Foobar.jpg\" src=\"//example.com/images/3/3a/Foobar.jpg\" 
data-file-width=\"1941\" data-file-height=\"220\" data-file-type=\"bitmap\" 
height=\"220\" width=\"1941\" 
data-parsoid='{\"a\":{\"resource\":\"./File:Foobar.jpg\",\"height\":\"220\",\"width\":\"1941\"},\"sa\":{\"resource\":\"File:Foobar.jpg\"}}'/></a></span></p>\n");
 add("html2html", "Image: caption containing a table", "<figure 
typeof=\"mw:Image/Thumb\" 
data-parsoid='{\"optList\":[{\"ck\":\"thumbnail\",\"ak\":\"thumb\"},{\"ck\":\"width\",\"ak\":\"200x200px\"},{\"ck\":\"bogus\",\"ak\":\"This
 is an example image thumbnail caption with a 
table\\n{\"},{\"ck\":\"bogus\",\"ak\":\"\\n\\n!Foo 
!Bar\\n\"},{\"ck\":\"bogus\",\"ak\":\"-\\n\"},{\"ck\":\"bogus\",\"ak\":\"Foo1 
\\n\"},{\"ck\":\"bogus\",\"ak\":\"Bar1\"},{\"ck\":\"caption\",\"ak\":\"}\\nand 
some more text.\"}],\"dsr\":[0,143,2,2]}'><a href=\"./File:Foobar.jpg\" 
data-parsoid='{\"a\":{\"href\":\"./File:Foobar.jpg\"},\"sa\":{},\"dsr\":[2,null,null,null]}'><img
 resource=\"./File:Foobar.jpg\" 
src=\"//example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg\" 
data-file-width=\"1941\" data-file-height=\"220\" data-file-type=\"bitmap\" 
height=\"23\" width=\"200\" 
data-parsoid='{\"a\":{\"resource\":\"./File:Foobar.jpg\",\"height\":\"23\",\"width\":\"200\"},\"sa\":{\"resource\":\"File:Foobar.jpg\"}}'/></a><figcaption
 data-parsoid='{\"dsr\":[null,141,null,null]}'>}\nand some more 
text.</figcaption></figure>\n");
 add("html2html", "Subpage link", "<p data-parsoid='{\"dsr\":[0,38,0,0]}'><a 
rel=\"mw:WikiLink\" href=\"./Wiki/Subpage_test/subpage\" title=\"Wiki/Subpage 
test/subpage\" 
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Wiki/Subpage_test/subpage\"},\"sa\":{\"href\":\"wiki/Subpage
 test/subpage\"},\"dsr\":[0,38,28,2]}'>/subpage</a></p>\n");
 add("html2html", "Subpage noslash link", "<p 
data-parsoid='{\"dsr\":[0,37,0,0]}'><a rel=\"mw:WikiLink\" 
href=\"./Wiki/Subpage_test/subpage\" title=\"Wiki/Subpage test/subpage\" 
data-parsoid='{\"stx\":\"piped\",\"a\":{\"href\":\"./Wiki/Subpage_test/subpage\"},\"sa\":{\"href\":\"wiki/Subpage
 test/subpage\"},\"dsr\":[0,37,28,2]}'>subpage</a></p>\n");
@@ -1918,8 +1915,6 @@
 add("selser", "Image with multiple widths -- use last [1]", 
"[[File:Foobar.jpg|200px|300px|caption]]");
 add("selser", "Image with width attribute at different positions 
[0,2,[0,1],3,0]", 
"[[File:Foobar.jpg|200px|right|Caption]]xmu7d955jxmndn29\n[[File:Foobar.jpg|right|200px|Caption]]\n[[File:Foobar.jpg|right|Caption|200px]]");
 add("selser", "Image with 'frame' first. [0,4,[0,1],3,0]", 
"[[File:Foobar.jpg|frame|caption]]7sa4l88rpsowp14i[[File:Foobar.jpg|frame|frameless|caption]]\n[[File:Foobar.jpg|frame|thumb|caption]]");
-add("selser", "T107474: Frameless image caption with <nowiki> [1]", 
"[[File:Foobar.jpg|<nowiki>text with a [[MeatBall:Link|link]] in 
it</nowiki>]]");
-add("selser", "T107474: Frameless image caption with <nowiki> [2]", 
"jkgmgz8no168ncdi\n\n[[File:Foobar.jpg|<nowiki>text with a 
[[MeatBall:Link|link]] in it</nowiki>]]");
 add("selser", "Render invalid page names as plain text (bug 51090) [0,0,1]", 
"[[./../foo|bar]]\n[[foo�|bar]]\n[[foo/.|bar]]\n[[foo/..|bar]]\n[[foo~~~bar]]\n[[foo>bar]]\n[[foo[bar]]\n[[.]]\n[[..]]\n[[foo././bar]]\n\n[[{{echo|./../foo}}|bar]]\n[[{{echo|foo/.}}|bar]]\n[[{{echo|foo/..}}|bar]]\n[[{{echo|foo~~~~bar}}]]\n[[{{echo|foo>bar}}]]\n[[{{echo|foo././bar}}]]\n[[{{echo|foo{bar}}]]\n[[{{echo|foo}bar}}]]\n[[{{echo|foo[bar}}]]\n[[{{echo|foo]bar}}]]\n[[{{echo|foo<bar}}]]");
 add("selser", "Render invalid page names as plain text (bug 51090) 
[2,2,[3,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0]]", 
"pwgl4v8r9af6flxr\n\n[[./../foo|bar]]\n[[foo�|bar]]\n[[foo/.|bar]]\n[[foo/..|bar]]\n[[foo~~~bar]]\n[[foo>bar]]\n[[foo[bar]]\n[[.]]\n[[..]]\n[[foo././bar]]\n\nhtc0s57znl9v0a4i\n\n{{echo|./../foo}}{{echo|foo/.}}|bar]]\n[[{{echo|foo/..}}|bar]]\n[[{{echo|foo~~~~bar}}]]\n[[{{echo|foo>bar}}]]\n[[{{echo|foo././bar}}]]\n[[{{echo|foo{bar}}]]\n[[{{echo|foo}bar}}]]\n[[{{echo|foo[bar}}{{echo|foo]bar}}]]\n[[{{echo|foo<bar}}]]");
 add("selser", "Render invalid page names as plain text (bug 51090) [0,3,2]", 
"[[./../foo|bar]]\n[[foo�|bar]]\n[[foo/.|bar]]\n[[foo/..|bar]]\n[[foo~~~bar]]\n[[foo>bar]]\n[[foo[bar]]\n[[.]]\n[[..]]\n[[foo././bar]]\n\ngkfu6gduolqmpldi\n\n[[{{echo|./../foo}}|bar]]\n[[{{echo|foo/.}}|bar]]\n[[{{echo|foo/..}}|bar]]\n[[{{echo|foo~~~~bar}}]]\n[[{{echo|foo>bar}}]]\n[[{{echo|foo././bar}}]]\n[[{{echo|foo{bar}}]]\n[[{{echo|foo}bar}}]]\n[[{{echo|foo[bar}}]]\n[[{{echo|foo]bar}}]]\n[[{{echo|foo<bar}}]]");
diff --git a/tests/parserTests.txt b/tests/parserTests.txt
index 5ca2221..0a5a7f6 100644
--- a/tests/parserTests.txt
+++ b/tests/parserTests.txt
@@ -13235,7 +13235,7 @@
 !! wikitext
 [[File:Foobar.jpg|<nowiki>text with a [[MeatBall:Link|link]] in it</nowiki>]]
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image mw:Placeholder" 
data-mw='{"caption":"&lt;span typeof=\"mw:Nowiki\">text with a 
[[MeatBall:Link|link]] in it&lt;/span>"}'><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="220" width="1941"/></a></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" 
data-mw='{"caption":"&lt;span typeof=\"mw:Nowiki\" 
data-parsoid=\"{&amp;quot;dsr&amp;quot;:[18,75,8,9]}\">text with a 
[[MeatBall:Link|link]] in it&lt;/span>"}'><a href="./File:Foobar.jpg"><img 
resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" 
data-file-width="1941" data-file-height="220" data-file-type="bitmap" 
height="220" width="1941"/></a></span></p>
 !! end
 
 !! test

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I33e4dacb0f55b19690db80a52a7af17560814757
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to