Browse Source

Remove scheme whitelist for autolinks

pull/204/merge
Alex Kocharin 9 years ago
parent
commit
0661eea828
  1. 172
      lib/common/url_schemas.js
  2. 6
      lib/rules_inline/autolink.js
  3. 42
      test/fixtures/commonmark/bad.txt
  4. 27
      test/fixtures/commonmark/good.txt

172
lib/common/url_schemas.js

@ -1,172 +0,0 @@
// List of valid url schemas, accorting to commonmark spec
// http://jgm.github.io/CommonMark/spec.html#autolinks
'use strict';
module.exports = [
'coap',
'doi',
'javascript',
'aaa',
'aaas',
'about',
'acap',
'cap',
'cid',
'crid',
'data',
'dav',
'dict',
'dns',
'file',
'ftp',
'geo',
'go',
'gopher',
'h323',
'http',
'https',
'iax',
'icap',
'im',
'imap',
'info',
'ipp',
'iris',
'iris.beep',
'iris.xpc',
'iris.xpcs',
'iris.lwz',
'ldap',
'mailto',
'mid',
'msrp',
'msrps',
'mtqp',
'mupdate',
'news',
'nfs',
'ni',
'nih',
'nntp',
'opaquelocktoken',
'pop',
'pres',
'rtsp',
'service',
'session',
'shttp',
'sieve',
'sip',
'sips',
'sms',
'snmp',
'soap.beep',
'soap.beeps',
'tag',
'tel',
'telnet',
'tftp',
'thismessage',
'tn3270',
'tip',
'tv',
'urn',
'vemmi',
'ws',
'wss',
'xcon',
'xcon-userid',
'xmlrpc.beep',
'xmlrpc.beeps',
'xmpp',
'z39.50r',
'z39.50s',
'adiumxtra',
'afp',
'afs',
'aim',
'apt',
'attachment',
'aw',
'beshare',
'bitcoin',
'bolo',
'callto',
'chrome',
'chrome-extension',
'com-eventbrite-attendee',
'content',
'cvs',
'dlna-playsingle',
'dlna-playcontainer',
'dtn',
'dvb',
'ed2k',
'facetime',
'feed',
'finger',
'fish',
'gg',
'git',
'gizmoproject',
'gtalk',
'hcp',
'icon',
'ipn',
'irc',
'irc6',
'ircs',
'itms',
'jar',
'jms',
'keyparc',
'lastfm',
'ldaps',
'magnet',
'maps',
'market',
'message',
'mms',
'ms-help',
'msnim',
'mumble',
'mvn',
'notes',
'oid',
'palm',
'paparazzi',
'platform',
'proxy',
'psyc',
'query',
'res',
'resource',
'rmi',
'rsync',
'rtmp',
'secondlife',
'sftp',
'sgn',
'skype',
'smb',
'soldat',
'spotify',
'ssh',
'steam',
'svn',
'teamspeak',
'things',
'udp',
'unreal',
'ut2004',
'ventrilo',
'view-source',
'webcal',
'wtai',
'wyciwyg',
'xfire',
'xri',
'ymsgr'
];

6
lib/rules_inline/autolink.js

@ -2,12 +2,10 @@
'use strict'; 'use strict';
var url_schemas = require('../common/url_schemas');
/*eslint max-len:0*/ /*eslint max-len:0*/
var EMAIL_RE = /^<([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/; var EMAIL_RE = /^<([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/;
var AUTOLINK_RE = /^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/; var AUTOLINK_RE = /^<([a-zA-Z][a-zA-Z0-9+.\-]{1,31}):([^<>\x00-\x20]*)>/;
module.exports = function autolink(state, silent) { module.exports = function autolink(state, silent) {
@ -23,8 +21,6 @@ module.exports = function autolink(state, silent) {
if (AUTOLINK_RE.test(tail)) { if (AUTOLINK_RE.test(tail)) {
linkMatch = tail.match(AUTOLINK_RE); linkMatch = tail.match(AUTOLINK_RE);
if (url_schemas.indexOf(linkMatch[1].toLowerCase()) < 0) { return false; }
url = linkMatch[0].slice(1, -1); url = linkMatch[0].slice(1, -1);
fullUrl = state.md.normalizeLink(url); fullUrl = state.md.normalizeLink(url);
if (!state.md.validateLink(fullUrl)) { return false; } if (!state.md.validateLink(fullUrl)) { return false; }

42
test/fixtures/commonmark/bad.txt

@ -55,45 +55,3 @@ error:
</ul> </ul>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 8248
.
<a+b+c:d>
.
<p><a href="a+b+c:d">a+b+c:d</a></p>
.
error:
<p>&lt;a+b+c:d&gt;</p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 8255
.
<made-up-scheme://foo,bar>
.
<p><a href="made-up-scheme://foo,bar">made-up-scheme://foo,bar</a></p>
.
error:
<p>&lt;made-up-scheme://foo,bar&gt;</p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 8269
.
<localhost:5001/foo>
.
<p><a href="localhost:5001/foo">localhost:5001/foo</a></p>
.
error:
<p>&lt;localhost:5001/foo&gt;</p>

27
test/fixtures/commonmark/good.txt

@ -6815,6 +6815,24 @@ src line: 8236
<p><a href="MAILTO:FOO@BAR.BAZ">MAILTO:FOO@BAR.BAZ</a></p> <p><a href="MAILTO:FOO@BAR.BAZ">MAILTO:FOO@BAR.BAZ</a></p>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 8248
.
<a+b+c:d>
.
<p><a href="a+b+c:d">a+b+c:d</a></p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 8255
.
<made-up-scheme://foo,bar>
.
<p><a href="made-up-scheme://foo,bar">made-up-scheme://foo,bar</a></p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 8262 src line: 8262
@ -6824,6 +6842,15 @@ src line: 8262
<p><a href="http://../">http://../</a></p> <p><a href="http://../">http://../</a></p>
. .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 8269
.
<localhost:5001/foo>
.
<p><a href="localhost:5001/foo">localhost:5001/foo</a></p>
.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src line: 8278 src line: 8278

Loading…
Cancel
Save