Handle <nowiki> and other markup consistently in image link/alt options
authorC. Scott Ananian <cscott@cscott.net>
Mon, 15 Oct 2018 20:39:19 +0000 (16:39 -0400)
committerLegoktm <legoktm@member.fsf.org>
Mon, 22 Oct 2018 15:26:36 +0000 (15:26 +0000)
commitad80f0bca27c2b0905b2b137977586bfab80db34
tree4d036799fe3e3280f26dfeacdb5965072cbaf250
parentc3089171b006962502a4c0ab156474dbe821b8a4
Handle <nowiki> and other markup consistently in image link/alt options

Use Parser::stripAltText() consistently to handle link and alt options
in both Parser::makeImage() and Parser::renderImageGallery().  This
ensures that link option text can use <nowiki> to escape problematic
text so that (for example) the following works:

```
[[File:Foobar.jpg|link=<nowiki>a''b''c</nowiki>|alt=<nowiki>a''b''c</nowiki>]]
<gallery>
File:Foobar.jpg|link=<nowiki>a''b''c</nowiki>|alt=<nowiki>a''b''c</nowiki>
</gallery>
```

Previously the handling of the link option in
Parser::renderImageGallery() used a bespoke `strip_tags` invocation
which didn't replace <nowiki>s, and the handling of the link option in
Parser::makeImage() didn't strip tags at all, nor did it replace
<nowiki>s.  For example, in Parser::makeImage() double quotes in
titles would be converted to embedded `<i>` tags before being passed
to Parser::parseLinkParameter(), with predictably poor results.

Tests added to confirm behavior of alt/link with HTML-escaped
entities and <nowiki>s exposed a bug in Remex: T207088.  Tests
will fail on PHP 7.0 until that is fixed.

Bug: T206940
Depends-On: Ide67bba20f771868c0e119cb2874464dcf1d758a
Change-Id: Ife4c0edaa85e0cb294c5d4c1e31d5d7d828d9df4
includes/parser/Parser.php
tests/parser/parserTests.txt