mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-23 13:56:44 +00:00
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:
parent
84d88b1f4e
commit
5235dbb322
2
resources/dist/main.js
vendored
2
resources/dist/main.js
vendored
File diff suppressed because one or more lines are too long
2
resources/dist/main.js.map.json
vendored
2
resources/dist/main.js.map.json
vendored
File diff suppressed because one or more lines are too long
|
@ -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;
|
||||
|
|
|
@ -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'
|
||||
} ],
|
||||
|
|
Loading…
Reference in a new issue