Merge "Use correct Sanitizer method for id/fragment escaping"

This commit is contained in:
jenkins-bot 2022-01-27 08:12:43 +00:00 committed by Gerrit Code Review
commit e0ccd777b0
3 changed files with 24 additions and 24 deletions

View file

@ -66,7 +66,7 @@ class AnchorFormatter {
* @return string
*/
private function normalizeKey( string $key ): string {
$ret = Sanitizer::escapeIdForAttribute( $key );
$ret = Sanitizer::escapeIdForLink( $key );
$ret = preg_replace( '/__+/', '_', $ret );
$ret = Sanitizer::safeEncodeAttribute( $ret );

View file

@ -49,23 +49,23 @@ wgFragmentMode=['html5']
<ref name="9&nbsp;pm">F</ref>
<references />
!! html/php
<p><sup id="cite_ref-nature%20phylo_1-0" class="reference"><a href="#cite_note-nature_phylo-1">&#91;1&#93;</a></sup>
<sup id="cite_ref-Mininova%2E26%2E11%2E2009_2-0" class="reference"><a href="#cite_note-Mininova.26.11.2009-2">&#91;2&#93;</a></sup>
<sup id="cite_ref-%c8%98tiri_2019_3-0" class="reference"><a href="#cite_note-Știri_2019-3">&#91;3&#93;</a></sup>
<sup id="cite_ref-play%21_4-0" class="reference"><a href="#cite_note-play!-4">&#91;4&#93;</a></sup>
<sup id="cite_ref-Terry+O%26rsquo%3BN…&lt;/ref_5-0" class="reference"><a href="#cite_note-Terry+ON…&lt;/ref-5">&#91;5&#93;</a></sup>
<p><sup id="cite_ref-nature%2520phylo_1-0" class="reference"><a href="#cite_note-nature%2520phylo-1">&#91;1&#93;</a></sup>
<sup id="cite_ref-Mininova%252E26%252E11%252E2009_2-0" class="reference"><a href="#cite_note-Mininova%252E26%252E11%252E2009-2">&#91;2&#93;</a></sup>
<sup id="cite_ref-%25c8%2598tiri_2019_3-0" class="reference"><a href="#cite_note-%25c8%2598tiri_2019-3">&#91;3&#93;</a></sup>
<sup id="cite_ref-play%2521_4-0" class="reference"><a href="#cite_note-play%2521-4">&#91;4&#93;</a></sup>
<sup id="cite_ref-Terry+O%2526rsquo%253BN…&lt;/ref_5-0" class="reference"><a href="#cite_note-Terry+O%2526rsquo%253BN…&lt;/ref-5">&#91;5&#93;</a></sup>
<sup id="cite_ref-9&#160;pm_6-0" class="reference"><a href="#cite_note-9_pm-6">&#91;6&#93;</a></sup>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-nature%20phylo-1"><span class="mw-cite-backlink"><a href="#cite_ref-nature_phylo_1-0">↑</a></span> <span class="reference-text">A</span>
<li id="cite_note-nature%2520phylo-1"><span class="mw-cite-backlink"><a href="#cite_ref-nature%2520phylo_1-0">↑</a></span> <span class="reference-text">A</span>
</li>
<li id="cite_note-Mininova%2E26%2E11%2E2009-2"><span class="mw-cite-backlink"><a href="#cite_ref-Mininova.26.11.2009_2-0">↑</a></span> <span class="reference-text">B</span>
<li id="cite_note-Mininova%252E26%252E11%252E2009-2"><span class="mw-cite-backlink"><a href="#cite_ref-Mininova%252E26%252E11%252E2009_2-0">↑</a></span> <span class="reference-text">B</span>
</li>
<li id="cite_note-%c8%98tiri_2019-3"><span class="mw-cite-backlink"><a href="#cite_ref-Știri_2019_3-0">↑</a></span> <span class="reference-text">C</span>
<li id="cite_note-%25c8%2598tiri_2019-3"><span class="mw-cite-backlink"><a href="#cite_ref-%25c8%2598tiri_2019_3-0">↑</a></span> <span class="reference-text">C</span>
</li>
<li id="cite_note-play%21-4"><span class="mw-cite-backlink"><a href="#cite_ref-play!_4-0">↑</a></span> <span class="reference-text">D</span>
<li id="cite_note-play%2521-4"><span class="mw-cite-backlink"><a href="#cite_ref-play%2521_4-0">↑</a></span> <span class="reference-text">D</span>
</li>
<li id="cite_note-Terry+O%26rsquo%3BN…&lt;/ref-5"><span class="mw-cite-backlink"><a href="#cite_ref-Terry+ON…&lt;/ref_5-0">↑</a></span> <span class="reference-text">E</span>
<li id="cite_note-Terry+O%2526rsquo%253BN…&lt;/ref-5"><span class="mw-cite-backlink"><a href="#cite_ref-Terry+O%2526rsquo%253BN…&lt;/ref_5-0">↑</a></span> <span class="reference-text">E</span>
</li>
<li id="cite_note-9&#160;pm-6"><span class="mw-cite-backlink"><a href="#cite_ref-9_pm_6-0">↑</a></span> <span class="reference-text">F</span>
</li>
@ -89,17 +89,17 @@ wgFragmentMode=['legacy']
!! end
!! test
FIXME: Double URL encoding in HTML5 mode
Double URL encoding in HTML5 mode
!! config
wgFragmentMode=['html5']
!! wikitext
<ref name="n%25%32%30n" group="g%25%32%30g">A</ref>
<references group="g%25%32%30g" />
!! html/php
<p><sup id="cite_ref-n%25%32%30n_1-0" class="reference"><a href="#cite_note-n%2520n-1">&#91;g%25%32%30g 1&#93;</a></sup>
<p><sup id="cite_ref-n%2525%2532%2530n_1-0" class="reference"><a href="#cite_note-n%2525%2532%2530n-1">&#91;g%25%32%30g 1&#93;</a></sup>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-n%25%32%30n-1"><span class="mw-cite-backlink"><a href="#cite_ref-n%2520n_1-0">↑</a></span> <span class="reference-text">A</span>
<li id="cite_note-n%2525%2532%2530n-1"><span class="mw-cite-backlink"><a href="#cite_ref-n%2525%2532%2530n_1-0">↑</a></span> <span class="reference-text">A</span>
</li>
</ol></div>
!! end
@ -121,17 +121,17 @@ wgFragmentMode=['legacy']
!! end
!! test
FIXME: Multiple, partly encoded spaces in HTML5 mode
Multiple, partly encoded spaces in HTML5 mode
!! config
wgFragmentMode=['html5']
!! wikitext
<ref name="a_ %20a" group="b_ %20b">A</ref>
<references group="b_ %20b" />
!! html/php
<p><sup id="cite_ref-a_%20a_1-0" class="reference"><a href="#cite_note-a_a-1">&#91;b_ %20b 1&#93;</a></sup>
<p><sup id="cite_ref-a_%2520a_1-0" class="reference"><a href="#cite_note-a_%2520a-1">&#91;b_ %20b 1&#93;</a></sup>
</p>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-a_%20a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_a_1-0">↑</a></span> <span class="reference-text">A</span>
<li id="cite_note-a_%2520a-1"><span class="mw-cite-backlink"><a href="#cite_ref-a_%2520a_1-0">↑</a></span> <span class="reference-text">A</span>
</li>
</ol></div>
!! end

View file

@ -87,14 +87,14 @@ class AnchorFormatterTest extends \MediaWikiUnitTestCase {
[ '"%&/<>?[]{|}', '&quot;%&amp;/&lt;&gt;?&#91;&#93;&#123;&#124;&#125;' ],
[ 'ISBN', '&#73;SBN' ],
[ 'nature%20phylo', 'nature%20phylo' ],
[ 'Mininova%2E26%2E11%2E2009', 'Mininova%2E26%2E11%2E2009' ],
[ '%c8%98tiri_2019', '%c8%98tiri_2019' ],
[ 'play%21', 'play%21' ],
[ 'Terry+O%26rsquo%3BN…</ref', 'Terry+O%26rsquo%3BN…&lt;/ref' ],
[ 'nature%20phylo', 'nature%2520phylo' ],
[ 'Mininova%2E26%2E11%2E2009', 'Mininova%252E26%252E11%252E2009' ],
[ '%c8%98tiri_2019', '%25c8%2598tiri_2019' ],
[ 'play%21', 'play%2521' ],
[ 'Terry+O%26rsquo%3BN…</ref', 'Terry+O%2526rsquo%253BN…&lt;/ref' ],
[ '9&nbsp;pm', '9&amp;nbsp;pm' ],
[ 'n%25%32%30n', 'n%25%32%30n' ],
[ 'a_ %20a', 'a_%20a' ],
[ 'n%25%32%30n', 'n%2525%2532%2530n' ],
[ 'a_ %20a', 'a_%2520a' ],
];
}