Images: Links in alt (and maybe other) attributes of images generates incorrect HTML
Closed, ResolvedPublic

Description

en.wp user User:Timwi reports

"On the page [[Earth]], we had the following markup code:

[[File:(filename)|thumb|700px|center| (caption here) |alt= (alt text here) ]]

The VisualEditor parsed this incorrectly and assumed that “alt= (alt text here)” was the ''caption''.

Changing the order of the items fixed this despite having no effect on the rendered page, which indicates that it’s a bug in VisualEditor and not incorrect MediaWiki markup." http://en.wikipedia.org/w/index.php?title=Earth&diff=566614668&oldid=566595613

I've done some testing in my sandbox and it seems like the issue is somehow related to the presence of the {{val}} template. I wasn't able to replicate the bug with the {{small}} or {{convert}} templates for example, but I've not done extensive testing with the latter or with any other template.

https://en.wikipedia.org/w/index.php?title=User:Thryduulf/sandbox&oldid=566618437&veaction=edit


Version: unspecified
Severity: normal
URL: http://parsoid-lb.eqiad.wikimedia.org/enwiki/User:Thryduulf/sandbox?oldid=566618437

bzimport added a project: Parsoid.Via ConduitNov 22 2014, 2:08 AM
bzimport set Reference to bz52341.
Thryduulf created this task.Via LegacyJul 31 2013, 7:57 PM
ssastry added a comment.Via ConduitJul 24 2014, 9:08 PM

Verified fixed in deployed Parsoid version.

ssastry added a comment.Via ConduitJul 24 2014, 9:13 PM

Never mind. My eyes deceived me. The following snippet still parses incorrectly.

[[File:Solar Life Cycle.svg|thumb|700px|center|The life cycle of the Sun|alt=14 billion year timeline showing Sun's present age at {{val|4.6|ul=byr}}; from {{val|6|u=byr}} Sun gradually warming, becoming a red dwarf at, "soon" followed by its transformation into a white dwarf star]]

ssastry added a comment.Via WebFeb 3 2015, 10:49 PM

The problem seems to be with the link that the val template emits and Parsoid is somehow barfing on it. Can be reproduced with the following reduced test case:

[[File:Foo.jpg|thumb|Caption here|alt=This {{echo|[[will]]}} break]]

Compare with output of

[[File:Foo.jpg|thumb|Caption here|alt=This {{echo|will not}} break]]
ssastry changed the title from "Images: alt text instead becomes the caption if it is last and contains the {{val}} template" to "Images: Presence of link wikitext in alt (and maybe other) attributes of images leads to incorrect HTML for the image".Via WebFeb 3 2015, 10:50 PM
ssastry set Security to None.
ssastry moved this task to VE Q3 on the Parsoid workboard.
Jdforrester-WMF set Story Points to 0.Via WebFeb 10 2015, 8:31 PM
cscott added a subscriber: cscott.Via WebFeb 11 2015, 5:09 PM
cscott changed the title from "Images: Presence of link wikitext in alt (and maybe other) attributes of images leads to incorrect HTML for the image" to "Images: Presence of template-generated link wikitext in alt (and maybe other) attributes of images leads to incorrect HTML for the image".Via WebFeb 19 2015, 6:06 PM
ssastry added a comment.EditedVia WebMar 9 2015, 9:44 PM

This is a difference in how links are handled in alt-attributes, and nothing to do with templates.

[subbu@earth tests] echo '[[File:Foo.jpg|thumb|Caption here|alt=Foo ]]' | node parse --fetchConfig false --normalize=parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="File:Foo.jpg"><img alt="Foo" resource="./File:Foo.jpg" src="//upload.wikimedia.org/wikipedia/commons/0/06/Foo.jpg" height="144" width="220"/></a><figcaption>Caption here</figcaption></figure>

[subbu@earth tests] echo '[[File:Foo.jpg|thumb|Caption here|alt=[[Foo]] ]]' | node parse --fetchConfig false --normalize=parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="File:Foo.jpg"><img resource="./File:Foo.jpg" src="//upload.wikimedia.org/wikipedia/commons/0/06/Foo.jpg" height="144" width="220"/></a><figcaption>alt=<a rel="mw:WikiLink" href="Foo" title="Foo">Foo</a> </figcaption></figure>

[subbu@earth tests] echo '[[File:Foo.jpg|thumb|Caption here|alt={{echo|[[Foo]]}} ]]' | node parse --fetchConfig false --normalize=parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="File:Foo.jpg"><img resource="./File:Foo.jpg" src="//upload.wikimedia.org/wikipedia/commons/0/06/Foo.jpg" height="144" width="220"/></a><figcaption>alt=<a rel="mw:WikiLink" href="Foo" title="Foo" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Foo]]"}},"i":0}}]}'>Foo</a> </figcaption></figure>

However, the PHP parser generates identical HTML for the "alt=Foo" and "alt=[[Foo]]" cases above.

ssastry changed the title from "Images: Presence of template-generated link wikitext in alt (and maybe other) attributes of images leads to incorrect HTML for the image" to "Images: Links in alt (and maybe other) attributes of images generates incorrect HTML".Via WebMar 9 2015, 9:46 PM
ssastry claimed this task.Via WebMar 16 2015, 5:58 PM
gerritbot added a subscriber: gerritbot.Via ConduitMar 16 2015, 7:42 PM

Change 197120 had a related patch set uploaded (by Subramanya Sastry):
WIP: T54341: Recover content from non-string tokens for img option alt

https://gerrit.wikimedia.org/r/197120

gerritbot added a project: Patch-For-Review.Via ConduitMar 16 2015, 7:42 PM
gerritbot added a comment.Via ConduitMar 17 2015, 4:11 PM

Change 197120 merged by jenkins-bot:
T54341: Recover content from non-string tokens for img option alt

https://gerrit.wikimedia.org/r/197120

ssastry closed this task as "Resolved".Via WebMar 17 2015, 11:15 PM

Done now. Will be deployed tomorrow after a round of RT-testing. Can be reopened, if necessary.

Jdforrester-WMF moved this task to Done on the VisualEditor 2014/15 Q3 blockers workboard.Via WebMar 18 2015, 12:22 AM

Add Comment