Report both nested <ref> and <references> as an error

Before, this regular expression was looking for incomplete wikitext
like this:

<ref>unclosed
<ref>closed</ref>

With this change, wikitext like this will trigger the same error:

<ref>unclosed
<references />
incomplete</ref>

This should be much, much more rare. But I feel it's reasonable to mark
this as an error, instead of just rendering the broken inner tag in
plain text.

This patch also replaces `.*?>` with `[^>]*+>`. Both do the exact same.
Instead of doing an "ungreedy search for the first possible closing
bracket", which might cause backtracking, the new syntax consumes all
non-brackets before expecting one. This is guaranteed to never backtrack
(guaranteed by the extra +), and potentially faster because of this.

Change-Id: Ic76a52cd111b28e4522f095ce3984e3583f602c1
This commit is contained in:
Thiemo Kreuz 2019-12-09 11:29:40 +01:00
parent aa12b53e3e
commit 7c1849d7b0

View file

@ -206,8 +206,8 @@ class Cite {
} }
if ( preg_match( if ( preg_match(
'/<ref\b.*?>/i', '/<ref(erences)?\b[^>]*+>/i',
preg_replace( '#<(\w++).*?>.*?</\1\s*>|<!--.*?-->#s', '', $text ) preg_replace( '#<(\w++)[^>]*+>.*?</\1\s*>|<!--.*?-->#s', '', $text )
) ) { ) ) {
// (bug T8199) This most likely implies that someone left off the // (bug T8199) This most likely implies that someone left off the
// closing </ref> tag, which will cause the entire article to be // closing </ref> tag, which will cause the entire article to be