mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-23 22:45:20 +00:00
Sanitize underscores as core does, to not create broken links
Core sanitizes link targets and removes double spaces and underscores. But the corresponding id="…" attributes are not sanitized the same way. This results in broken links. This patch is not perfect (two references with name="a_b" and name="a__b" will conflict), but the best solution I can think of at the moment. Bug: T184912 Change-Id: I9dbc916ad99269517d84c8ffb8581628d44a9f4e
This commit is contained in:
parent
8b97f74dc9
commit
2b34dede6c
|
@ -1078,6 +1078,7 @@ class Cite {
|
|||
*/
|
||||
private function normalizeKey( $key ) {
|
||||
$key = Sanitizer::escapeIdForAttribute( $key );
|
||||
$key = preg_replace( '/__+/', '_', $key );
|
||||
$key = Sanitizer::safeEncodeAttribute( $key );
|
||||
|
||||
return $key;
|
||||
|
|
|
@ -271,6 +271,21 @@ Ref names containing a number
|
|||
|
||||
!! end
|
||||
|
||||
!! test
|
||||
T184912: Consistent normalization of consecutive underscores
|
||||
!! wikitext
|
||||
<ref name="x__x">example</ref>
|
||||
<references />
|
||||
!! html
|
||||
<p><sup id="cite_ref-x_x_1-0" class="reference"><a href="#cite_note-x_x-1">[1]</a></sup>
|
||||
</p>
|
||||
<div class="mw-references-wrap"><ol class="references">
|
||||
<li id="cite_note-x_x-1"><span class="mw-cite-backlink"><a href="#cite_ref-x_x_1-0">↑</a></span> <span class="reference-text">example</span>
|
||||
</li>
|
||||
</ol></div>
|
||||
|
||||
!! end
|
||||
|
||||
!! test
|
||||
Erroneous refs
|
||||
!! wikitext
|
||||
|
|
Loading…
Reference in a new issue