Block de-facto empty <ref> as if it's empty

The use case we care about is this:
<ref extends="some_book"> </ref>

It doesn't make sense that works, but the following doesn't:
<ref extends="some_book"></ref>

We decided that both need to behave the same.

For consistency this patch is applying the same change to all references,
no matter if they use the extends attribute or not. This is an actual
change and might make existing wikitext render differently. However, I
would like to argue that all wikitext that was using this was broken. The
effect of a <ref> </ref> with some whitespace is that the <references>
section at the end of the article will contain – well – an empty footnote.

Bug: T237241
Change-Id: Iaee35583eabcb416b0a06849b89ebbfb0fb7fef9
This commit is contained in:
Thiemo Kreuz 2019-11-20 15:44:12 +01:00 committed by Thiemo Kreuz (WMDE)
parent 8e800a8988
commit b10dd4ec27
3 changed files with 7 additions and 7 deletions

View file

@ -256,7 +256,8 @@ class Cite {
return '';
}
if ( $text === '' ) {
// @phan-suppress-next-line PhanImpossibleTypeComparison false positive
if ( $text !== null && trim( $text ) === '' ) {
# <ref ...></ref>. This construct is invalid if
# it's a contentful ref, but OK if it's a named duplicate and should
# be equivalent <ref ... />, for compatability with #tag.
@ -862,7 +863,7 @@ class Cite {
* @return string
*/
private function referenceText( $key, $text ) {
if ( $text === null || $text === '' ) {
if ( trim( $text ) === '' ) {
if ( $this->mParser->getOptions()->getIsSectionPreview() ) {
return $this->errorReporter->wikitext( 'cite_warning_sectionpreview_no_text', $key );
}

View file

@ -254,12 +254,11 @@ wgCiteBookReferencing=true
<ref extends="foo"> </ref>
!! html/php
<p><sup id="cite_ref-foo_1-0" class="reference"><a href="#cite_note-foo-1">&#91;1&#93;</a></sup>
<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code>&lt;ref&gt;</code> tag;
</p>
<sup id="cite_ref-2" class="reference"><a href="#cite_note-2">&#91;2&#93;</a></sup><div class="mw-references-wrap"><ol class="references">
refs with no name must have content</span><div class="mw-references-wrap"><ol class="references">
<li id="cite_note-foo-1"><span class="mw-cite-backlink"><a href="#cite_ref-foo_1-0">↑</a></span> <span class="reference-text">book</span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><a href="#cite_ref-2">↑</a></span> <span class="reference-text"> </span>
</li>
</ol></div>
!! end

View file

@ -547,7 +547,7 @@ refs with no name must have content</span>
!! test
<ref> with an empty-string name parameter and no content.
!! wikitext
Bla.<ref name=""></ref>
Bla.<ref name=""> </ref>
!! html
<p>Bla.<span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code>&lt;ref&gt;</code> tag;
refs with no name must have content</span>
@ -557,7 +557,7 @@ refs with no name must have content</span>
!! test
<ref> with a non-empty name parameter and no content.
!! wikitext
Bla.<ref name="void"></ref>
Bla.<ref name="void"> </ref>
!! html
Bla.<sup id="cite_ref-void_1-0" class="reference"><a href="#cite_note-void-1">&#91;1&#93;</a></sup><div class="mw-references-wrap"><ol class="references">
<li id="cite_note-void-1"><span class="mw-cite-backlink"><a href="#cite_ref-void_1-0">↑</a></span> <span class="error mw-ext-cite-error" lang="en" dir="ltr">Cite error: Invalid <code>&lt;ref&gt;</code> tag;