Page MenuHomePhabricator

Images: Links in alt (and maybe other) attributes of images generates incorrect HTML
Closed, ResolvedPublic0 Estimated Story Points

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

Details

Reference
bz52341

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:08 AM
bzimport added a project: Parsoid.
bzimport set Reference to bz52341.

Verified fixed in deployed Parsoid version.

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]]

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 renamed this task 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.Feb 3 2015, 10:50 PM
ssastry moved this task from Needs Triage to VE Q3 on the Parsoid board.
ssastry set Security to None.
cscott renamed this task 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.Feb 19 2015, 6:06 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 renamed this task 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.Mar 9 2015, 9:46 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

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

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

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