Fix MediaWiki highlighter partly failing on quoted attributes

In T270880 an example with a slash in <ref name="a/b"> is
described. The same issue happens with several other characters
including the closing bracket, e.g. <ref name="a>b">. This patch
fixes all of this by accepting _all_ characters between double
and single quotes.

Bug: T270880
Change-Id: I03a1e1a25af692dc703b44a57b2d23d6fc15c8c9
This commit is contained in:
Thiemo Kreuz 2021-04-23 20:43:33 +02:00
parent 6e6356ccc0
commit 032bed3c61
2 changed files with 7 additions and 2 deletions

View file

@ -422,7 +422,7 @@
function eatHtmlTagAttribute( name ) {
return function ( stream, state ) {
if ( stream.match( /^[^>/<{&~]+/ ) ) {
if ( stream.match( /^(?:"[^"]*"|'[^']*'|[^>/<{&~])+/ ) ) {
return makeLocalStyle( 'mw-htmltag-attribute', state );
}
if ( stream.eat( '>' ) ) {
@ -442,7 +442,7 @@
function eatExtTagAttribute( name ) {
return function ( stream, state ) {
if ( stream.match( /^[^>/<{&~]+/ ) ) {
if ( stream.match( /^(?:"[^"]*"|'[^']*'|[^>/<{&~])+/ ) ) {
return makeLocalStyle( 'mw-exttag-attribute mw-ext-' + name, state );
}
if ( stream.eat( '>' ) ) {

View file

@ -15,6 +15,11 @@
input: 'this is <p><div>content</p></p>',
output: '<pre class=" CodeMirror-line " role="presentation"><span role="presentation">this is <span class="cm-mw-htmltag-bracket">&lt;</span><span class="cm-mw-htmltag-name">p</span><span class="cm-mw-htmltag-bracket">&gt;&lt;</span><span class="cm-mw-htmltag-name">div</span><span class="cm-mw-htmltag-bracket">&gt;</span>content<span class="cm-error">&lt;/p</span>&gt;<span class="cm-mw-htmltag-bracket">&lt;/</span><span class="cm-mw-htmltag-name">p</span><span class="cm-mw-htmltag-bracket">&gt;</span></span></pre>'
},
{
title: 'HTML and ref tag attributes',
input: '<span title="a>b"><ref name="a>b"/></span>',
output: '<pre class=" CodeMirror-line " role="presentation"><span role="presentation"><span class="cm-mw-htmltag-bracket">&lt;</span><span class="cm-mw-htmltag-name">span </span><span class="cm-mw-htmltag-attribute">title="a&gt;b"</span><span class="cm-mw-htmltag-bracket">&gt;</span><span class="cm-mw-exttag-bracket cm-mw-ext-ref">&lt;</span><span class="cm-mw-exttag-name cm-mw-ext-ref">ref </span><span class="cm-mw-exttag-attribute cm-mw-ext-ref">name="a&gt;b"</span><span class="cm-mw-exttag-bracket cm-mw-ext-ref">/&gt;</span><span class="cm-mw-htmltag-bracket">&lt;/</span><span class="cm-mw-htmltag-name">span</span><span class="cm-mw-htmltag-bracket">&gt;</span></span></pre>'
},
{
title: 'indented table with caption and inline headings',
input: ' ::{| class="wikitable"\n |+ Caption\n |-\n ! Uno !! Dos\n |-\n | Foo || Bar\n |}',