jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/390356 )
Change subject: Don't break when reference names contain []
......................................................................
Don't break when reference names contain []
Bug: T29694
Bug: T179544
Depends-On: I189bdefbc9034cf8d221a89d7158195de1c0fa6c
Change-Id: Iec3439f76ecc2a3543b30b35f8735c92b0cfb711
---
M includes/Cite.php
M tests/parser/citeParserTests.txt
2 files changed, 42 insertions(+), 14 deletions(-)
Approvals:
C. Scott Ananian: Looks good to me, approved
jenkins-bot: Verified
Jforrester: Looks good to me, but someone else must approve
diff --git a/includes/Cite.php b/includes/Cite.php
index 126380e..e75eb2d 100644
--- a/includes/Cite.php
+++ b/includes/Cite.php
@@ -411,13 +411,13 @@
}
if ( isset( $argv['name'] ) ) {
// Key given.
- $key = Sanitizer::escapeIdForAttribute(
$argv['name'] );
+ $key = trim( $argv['name'] );
unset( $argv['name'] );
--$cnt;
}
if ( isset( $argv['follow'] ) ) {
// Follow given.
- $follow = Sanitizer::escapeIdForAttribute(
$argv['follow'] );
+ $follow = trim( $argv['follow'] );
unset( $argv['follow'] );
--$cnt;
}
@@ -814,10 +814,10 @@
if ( !is_array( $val ) ) {
return wfMessage(
'cite_references_link_one',
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
self::getReferencesKey( $key )
),
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
$this->refKey( $key )
),
$this->referenceText( $key, $val )
@@ -827,7 +827,7 @@
if ( isset( $val['follow'] ) ) {
return wfMessage(
'cite_references_no_link',
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
self::getReferencesKey(
$val['follow'] )
),
$text
@@ -836,7 +836,7 @@
if ( !isset( $val['count'] ) ) {
// this handles the case of section preview for
list-defined references
return wfMessage( 'cite_references_link_many',
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
self::getReferencesKey( $key .
"-" . ( isset( $val['key'] ) ? $val['key'] : '' ) )
),
'',
@@ -846,10 +846,10 @@
if ( $val['count'] < 0 ) {
return wfMessage(
'cite_references_link_one',
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
self::getReferencesKey(
$val['key'] )
),
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
# $this->refKey( $val['key'],
$val['count'] )
$this->refKey( $val['key'] )
),
@@ -863,10 +863,10 @@
if ( $val['count'] === 0 ) {
return wfMessage(
'cite_references_link_one',
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
self::getReferencesKey( $key .
"-" . $val['key'] )
),
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
# $this->refKey( $key,
$val['count'] ),
$this->refKey( $key,
$val['key'] . "-" . $val['count'] )
),
@@ -879,7 +879,7 @@
for ( $i = 0; $i <= $val['count']; ++$i ) {
$links[] = wfMessage(
'cite_references_link_many_format',
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
$this->refKey( $key,
$val['key'] . "-$i" )
),
$this->referencesFormatEntryNumericBacklinkLabel( $val['number'], $i,
$val['count'] ),
@@ -890,7 +890,7 @@
$list = $this->listToText( $links );
return wfMessage( 'cite_references_link_many',
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
self::getReferencesKey( $key . "-" .
$val['key'] )
),
$list,
@@ -1049,10 +1049,10 @@
$this->mParser->recursiveTagParse(
wfMessage(
'cite_reference_link',
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
$this->refKey( $key, $count )
),
- Sanitizer::safeEncodeAttribute(
+ $this->normalizeKey(
self::getReferencesKey( $key .
$subkey )
),
Sanitizer::safeEncodeAttribute(
@@ -1064,6 +1064,19 @@
}
/**
+ * Normalizes and sanitizes a reference key
+ *
+ * @param string $key
+ * @return string
+ */
+ private function normalizeKey( $key ) {
+ $key = Sanitizer::escapeIdForAttribute( $key );
+ $key = Sanitizer::safeEncodeAttribute( $key );
+
+ return $key;
+ }
+
+ /**
* This does approximately the same thing as
* Language::listToText() but due to this being used for a
* slightly different purpose (people might not want , as the
diff --git a/tests/parser/citeParserTests.txt b/tests/parser/citeParserTests.txt
index a5ad0ee..c3f97a7 100644
--- a/tests/parser/citeParserTests.txt
+++ b/tests/parser/citeParserTests.txt
@@ -608,6 +608,21 @@
!! end
+!! test
+T29694 - [] in reference names in HTML5 fragment mode
+!! config
+wgFragmentMode=[ 'html5' ]
+!! wikitext
+<ref name="[#foo] {bar} <baz>">[bar]</ref>
+!! html
+<sup id="cite_ref-[#foo]_{bar}_<baz_1-0"
class="reference"><a
href="#cite_note-[#foo]_{bar}_<baz-1">[1]</a></sup><div
class="mw-references-wrap"><ol class="references">
+<li id="cite_note-[#foo]_{bar}_<baz-1"><span
class="mw-cite-backlink"><a
href="#cite_ref-[#foo]_{bar}_<baz_1-0">↑</a></span> <span
class="reference-text">">[bar]</span>
+</li>
+</ol></div>
+
+!! end
+
+
#### ----------------------------------------------------------------
#### Parsoid-only testing of Parsoid's impl of <ref> and <references>
#### tags. Parsoid's output for these tags differs from that of the
--
To view, visit https://gerrit.wikimedia.org/r/390356
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iec3439f76ecc2a3543b30b35f8735c92b0cfb711
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Cite
Gerrit-Branch: master
Gerrit-Owner: MaxSem <[email protected]>
Gerrit-Reviewer: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits