Fix regular expressions not being case-insensitive

The "parser marker" placeholders are case-sensitive, e.g. for a tag
that's written like <rEf> the placeholder will also say …-rEf-…. This
was really just a mistake.

The error is as old as this code is. Added in commit 75004e33 in
2009.

Note we shouldn't use /i at the end because the marker itself should
not be case-insensitive. Only the tag name.

Instead of adding more (slow) test cases I update two that are
exactly about this part of Cite (nested tags) anyway.

Bug: T64335
Change-Id: I44c7a42a0da682a1082952fd1af817bf7d45378c
This commit is contained in:
thiemowmde 2023-12-11 17:23:16 +01:00
parent ae88f14aae
commit 6a18eac513
3 changed files with 7 additions and 6 deletions

View file

@ -420,7 +420,7 @@ class Cite {
$this->inReferencesGroup = $group ?? self::DEFAULT_GROUP;
if ( $text !== null && trim( $text ) !== '' ) {
if ( str_contains( $text, Parser::MARKER_PREFIX . "-references-" ) ) {
if ( preg_match( '{' . preg_quote( Parser::MARKER_PREFIX ) . '-(?i:references)-}', $text ) ) {
return $this->errorReporter->halfParsed( $parser, 'cite_error_included_references' );
}
@ -430,7 +430,8 @@ class Cite {
// all known use cases, but not strictly enforced by the parser. It is possible that
// some unusual combination of #tag, <references> and conditional parser functions could
// be created that would lead to malformed references here.
$count = substr_count( $text, Parser::MARKER_PREFIX . "-ref-" );
preg_match_all( '{' . preg_quote( Parser::MARKER_PREFIX ) . '-(?i:ref)-}', $text, $matches );
$count = count( $matches[0] );
// Undo effects of calling <ref> while unaware of being contained in <references>
foreach ( $this->referenceStack->rollbackRefs( $count ) as $call ) {

View file

@ -6,7 +6,7 @@
"wt2html": "<div class=\"mw-references-wrap\" typeof=\"mw:Extension/references mw:Transclusion\" about=\"#mwt2\" data-parsoid='{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[0,44,null,null]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#tag:references\",\"function\":\"tag\"},\"params\":{\"1\":{\"wt\":\"\\n&lt;ref name=\\\"\\\">foo&lt;/ref>\\n\"}},\"i\":0}}]}'><ol class=\"mw-references references\" data-parsoid=\"{}\"><li about=\"#cite_note-1\" id=\"cite_note-1\" data-parsoid=\"{}\"><span rel=\"mw:referencedBy\" data-parsoid=\"{}\"></span> <span id=\"mw-reference-text-cite_note-1\" class=\"mw-reference-text\" data-parsoid=\"{}\">foo</span></li></ol></div>"
},
"T242437 - Nested references edge case, outer tag function with LDR": {
"wt2html": "<p data-parsoid='{\"dsr\":[0,18,0,0]}'><sup about=\"#mwt2\" class=\"mw-ref reference\" id=\"cite_ref-foo_1-0\" rel=\"dc:references\" typeof=\"mw:Extension/ref\" data-parsoid='{\"dsr\":[0,18,18,0]}' data-mw='{\"name\":\"ref\",\"attrs\":{\"name\":\"foo\"}}'><a href=\"./Parser_test#cite_note-foo-1\" style=\"counter-reset: mw-Ref 1;\" data-parsoid=\"{}\"><span class=\"mw-reflink-text\" data-parsoid=\"{}\">[1]</span></a></sup></p>\n<div class=\"mw-references-wrap\" typeof=\"mw:Extension/references mw:Transclusion\" about=\"#mwt5\" data-parsoid='{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[19,86,null,null]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#tag:references\",\"function\":\"tag\"},\"params\":{\"1\":{\"wt\":\"\\n &lt;ref name=\\\"foo\\\">bar&lt;/ref>\\n\\n &lt;references />\\n\"}},\"i\":0}}]}'><ol class=\"mw-references references\" data-parsoid=\"{}\"><li about=\"#cite_note-foo-1\" id=\"cite_note-foo-1\" data-parsoid=\"{}\"><a href=\"./Parser_test#cite_ref-foo_1-0\" rel=\"mw:referencedBy\" data-parsoid=\"{}\"><span class=\"mw-linkback-text\" data-parsoid=\"{}\">↑ </span></a> <span id=\"mw-reference-text-cite_note-foo-1\" class=\"mw-reference-text\" data-parsoid=\"{}\">bar</span></li></ol></div>"
"wt2html": "<p data-parsoid='{\"dsr\":[0,18,0,0]}'><sup about=\"#mwt2\" class=\"mw-ref reference\" id=\"cite_ref-foo_1-0\" rel=\"dc:references\" typeof=\"mw:Extension/ref\" data-parsoid='{\"dsr\":[0,18,18,0]}' data-mw='{\"name\":\"ref\",\"attrs\":{\"name\":\"foo\"}}'><a href=\"./Parser_test#cite_note-foo-1\" style=\"counter-reset: mw-Ref 1;\" data-parsoid=\"{}\"><span class=\"mw-reflink-text\" data-parsoid=\"{}\">[1]</span></a></sup></p>\n<div class=\"mw-references-wrap\" typeof=\"mw:Extension/references mw:Transclusion\" about=\"#mwt5\" data-parsoid='{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[19,86,null,null]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#tag:references\",\"function\":\"tag\"},\"params\":{\"1\":{\"wt\":\"\\n &lt;ref name=\\\"foo\\\">bar&lt;/ref>\\n\\n &lt;References />\\n\"}},\"i\":0}}]}'><ol class=\"mw-references references\" data-parsoid=\"{}\"><li about=\"#cite_note-foo-1\" id=\"cite_note-foo-1\" data-parsoid=\"{}\"><a href=\"./Parser_test#cite_ref-foo_1-0\" rel=\"mw:referencedBy\" data-parsoid=\"{}\"><span class=\"mw-linkback-text\" data-parsoid=\"{}\">↑ </span></a> <span id=\"mw-reference-text-cite_note-foo-1\" class=\"mw-reference-text\" data-parsoid=\"{}\">bar</span></li></ol></div>"
},
"T242437 - Nested references edge case, outer tag function, inner LDR": {
"wt2html": "<p data-parsoid='{\"dsr\":[0,18,0,0]}'><sup about=\"#mwt2\" class=\"mw-ref reference\" id=\"cite_ref-foo_1-0\" rel=\"dc:references\" typeof=\"mw:Extension/ref\" data-parsoid='{\"dsr\":[0,18,18,0]}' data-mw='{\"name\":\"ref\",\"attrs\":{\"name\":\"foo\"}}'><a href=\"./Parser_test#cite_note-foo-1\" style=\"counter-reset: mw-Ref 1;\" data-parsoid=\"{}\"><span class=\"mw-reflink-text\" data-parsoid=\"{}\">[1]</span></a></sup></p>\n<div class=\"mw-references-wrap\" typeof=\"mw:Extension/references mw:Transclusion\" about=\"#mwt4\" data-parsoid='{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[19,101,null,null]}' data-mw='{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#tag:references\",\"function\":\"tag\"},\"params\":{\"1\":{\"wt\":\"\\n &lt;references>\\n &lt;ref name=\\\"foo\\\">bar&lt;/ref>\\n &lt;/references>\\n\"}},\"i\":0}}]}'><ol class=\"mw-references references\" data-parsoid=\"{}\"><li about=\"#cite_note-foo-1\" id=\"cite_note-foo-1\" data-parsoid=\"{}\"><a href=\"./Parser_test#cite_ref-foo_1-0\" rel=\"mw:referencedBy\" data-parsoid=\"{}\"><span class=\"mw-linkback-text\" data-parsoid=\"{}\">↑ </span></a> <span id=\"mw-reference-text-cite_note-foo-1\" class=\"mw-reference-text\" data-parsoid=\"{}\">bar</span></li></ol></div>"

View file

@ -865,7 +865,7 @@ parsoid=wt2html
<ref name="foo" />
{{#tag:references|
<ref name="foo">BAR</ref>
<Ref name="foo">BAR</ref>
}}
!! html
<p><sup id="cite_ref-foo_1-0" class="reference"><a href="#cite_note-foo-1">&#91;1&#93;</a></sup>
@ -877,7 +877,7 @@ parsoid=wt2html
!! html/parsoid
<p><sup about="#mwt3" class="mw-ref reference" id="cite_ref-foo_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"foo"}}'><a href="./Parser_test#cite_note-foo-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup></p>
<div class="mw-references-wrap" typeof="mw:Extension/references mw:Transclusion" about="#mwt6" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#tag:references","function":"tag"},"params":{"1":{"wt":"\n&lt;ref name=\"foo\">BAR&lt;/ref>\n"}},"i":0}}]}'><ol class="mw-references references"><li about="#cite_note-foo-1" id="cite_note-foo-1"><a href="./Parser_test#cite_ref-foo_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-foo-1" class="mw-reference-text">BAR</span></li></ol></div>
<div class="mw-references-wrap" typeof="mw:Extension/references mw:Transclusion" about="#mwt6" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#tag:references","function":"tag"},"params":{"1":{"wt":"\n&lt;Ref name=\"foo\">BAR&lt;/ref>\n"}},"i":0}}]}'><ol class="mw-references references"><li about="#cite_note-foo-1" id="cite_note-foo-1"><a href="./Parser_test#cite_ref-foo_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-foo-1" class="mw-reference-text">BAR</span></li></ol></div>
!! end
# T307741: Parsoid fails this test in both standalone and integrated modes.
@ -888,7 +888,7 @@ T242437 - Nested references edge case, outer tag function with LDR
{{#tag:references|
<ref name="foo">bar</ref>
<references />
<References />
}}
!! html
<p><sup id="cite_ref-foo_1-0" class="reference"><a href="#cite_note-foo-1">&#91;1&#93;</a></sup>