fix protocol-like words not as URL protocol

A valid URL, whether free or not, requires at least 1 character after the protocol.

Bug: T309880
Change-Id: I972c4f0ea4273a3f50db17376af808770f28df0b
This commit is contained in:
bhsd 2024-01-19 02:06:06 +08:00
parent 84d88b1f4e
commit 5235dbb322
4 changed files with 9 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -21,7 +21,7 @@ class CodeMirrorModeMediaWiki {
constructor( config ) {
this.config = config;
// eslint-disable-next-line security/detect-non-literal-regexp
this.urlProtocols = new RegExp( `^(?:${ this.config.urlProtocols })`, 'i' );
this.urlProtocols = new RegExp( `^(?:${ this.config.urlProtocols })(?=[^\\s\u00a0{[\\]<>~).,'])`, 'i' );
this.isBold = false;
this.wasBold = false;
this.isItalic = false;

View file

@ -33,6 +33,11 @@ const testCases = [
input: 'https://wikimedia.org [ftp://foo.bar FOO] //archive.org',
output: '<div class="cm-line"><span class="cm-mw-free-extlink-protocol">https://</span><span class="cm-mw-free-extlink">wikimedia.</span><span class="cm-mw-free-extlink">org</span> <span class="cm-mw-link-ground cm-mw-extlink-bracket">[</span><span class="cm-mw-link-ground cm-mw-extlink-protocol">ftp://</span><span class="cm-mw-link-ground cm-mw-extlink">foo.bar</span><span class="cm-mw-link-ground"> </span><span class="cm-mw-link-ground cm-mw-extlink-text">FOO</span><span class="cm-mw-link-ground cm-mw-extlink-bracket">]</span> //archive.org</div>'
},
{
title: 'not free external links',
input: 'news: foo news:bar [news: baz]',
output: '<div class="cm-line">news: foo <span class="cm-mw-free-extlink-protocol">news:</span><span class="cm-mw-free-extlink">bar</span> [news: baz]</div>'
},
{
title: 'void tags',
input: 'a<br>b</br>c a<div>b<br>c</div>d',
@ -141,7 +146,7 @@ document.body.appendChild( textarea );
const cm = new CodeMirror( textarea );
// Stub the config normally provided by mw.config.get('extCodeMirrorConfig')
const mwLang = mediaWikiLang( {
urlProtocols: 'ftp://|https://',
urlProtocols: 'ftp://|https://|news:',
doubleUnderscore: [ {
__notoc__: 'notoc'
} ],