From 1bd66081f70fc90a4aaa82f65d6a33c68fee0db2 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Tue, 17 Dec 2019 13:04:50 +0100 Subject: [PATCH] Fix inconsistent error reporting for invisible content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes one of the last remaining edge-cases about non-empty, but non-visible content (a that only contains whitespace) behave identical to all other places. We already reported it as being empty everywhere else, except inside of . Note that the test cases look like they are reporting the same errors twice. But this is not the case: The first set of errors is about inside of not having visible content. This should always be reported, even if the got content from somewhere else on the page. The second set of errors is when a *never* got any content. This patch will slightly increase the numbers of errors reported. Change-Id: I4a156aa9e466f735d92fe0ba5cc0678ec8bbdd50 --- src/Cite.php | 5 +---- tests/parser/citeParserTests.txt | 33 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Cite.php b/src/Cite.php index efc50faa5..01aa56df5 100644 --- a/src/Cite.php +++ b/src/Cite.php @@ -241,10 +241,7 @@ class Cite { return StatusValue::newFatal( 'cite_error_references_no_key' ); } - // This doesn't catch the null case because that's guaranteed to trigger other errors - // FIXME: We allow whitespace-only text, should this be invalid? It leaves a - // loophole around the trimmed-text test outside of . - if ( $text === '' ) { + if ( $text === null || trim( $text ) === '' ) { // called in has no content. return StatusValue::newFatal( 'cite_error_empty_references_define', diff --git a/tests/parser/citeParserTests.txt b/tests/parser/citeParserTests.txt index 29e4a4156..dc7cb77e9 100644 --- a/tests/parser/citeParserTests.txt +++ b/tests/parser/citeParserTests.txt @@ -639,12 +639,43 @@ Attributes are trimmed by the parser, see Sanitizer::decodeTagAttributes()
  • Cite error: Invalid <ref> tag; no text was provided for refs named foo
  • -

    Cite error: <ref> tag with name "unused" defined in <references> is not used in prior text.
    +

    Cite error: <ref> tag defined in <references> with name "foo" has no content.
    +Cite error: <ref> tag with name "unused" defined in <references> is not used in prior text.
    Cite error: <ref> tag in <references> has conflicting group attribute "1".
    Cite error: <ref> tag defined in <references> has no name attribute.

    !! end +!! test +Error conditions on non-visible content +!! wikitext +x + + + + + + + +!! html +

    [1] +[2] +[3] +

    +
      +
    1. x +
    2. +
    3. Cite error: Invalid <ref> tag; +no text was provided for refs named b
    4. +
    5. Cite error: Invalid <ref> tag; +no text was provided for refs named c
    6. +
    +

    Cite error: <ref> tag defined in <references> with name "a" has no content.
    +Cite error: <ref> tag defined in <references> with name "b" has no content.
    +Cite error: <ref> tag defined in <references> with name "c" has no content. +

    +!! end + !! article MediaWiki:cite_link_label_group-klingon !! text