From 0661eea828066e87dc01728fe40d6ffe1cacfb8c Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Mon, 25 Jan 2016 14:27:05 +0300 Subject: [PATCH] Remove scheme whitelist for autolinks --- lib/common/url_schemas.js | 172 ------------------------------ lib/rules_inline/autolink.js | 6 +- test/fixtures/commonmark/bad.txt | 42 -------- test/fixtures/commonmark/good.txt | 27 +++++ 4 files changed, 28 insertions(+), 219 deletions(-) delete mode 100644 lib/common/url_schemas.js diff --git a/lib/common/url_schemas.js b/lib/common/url_schemas.js deleted file mode 100644 index bd71c25..0000000 --- a/lib/common/url_schemas.js +++ /dev/null @@ -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' -]; diff --git a/lib/rules_inline/autolink.js b/lib/rules_inline/autolink.js index 726c9ea..1f0c466 100644 --- a/lib/rules_inline/autolink.js +++ b/lib/rules_inline/autolink.js @@ -2,12 +2,10 @@ 'use strict'; -var url_schemas = require('../common/url_schemas'); - /*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 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) { @@ -23,8 +21,6 @@ module.exports = function autolink(state, silent) { if (AUTOLINK_RE.test(tail)) { linkMatch = tail.match(AUTOLINK_RE); - if (url_schemas.indexOf(linkMatch[1].toLowerCase()) < 0) { return false; } - url = linkMatch[0].slice(1, -1); fullUrl = state.md.normalizeLink(url); if (!state.md.validateLink(fullUrl)) { return false; } diff --git a/test/fixtures/commonmark/bad.txt b/test/fixtures/commonmark/bad.txt index 94b7097..f6b4edf 100644 --- a/test/fixtures/commonmark/bad.txt +++ b/test/fixtures/commonmark/bad.txt @@ -55,45 +55,3 @@ error: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 8248 - -. - -. -

a+b+c:d

-. - -error: - -

<a+b+c:d>

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 8255 - -. - -. -

made-up-scheme://foo,bar

-. - -error: - -

<made-up-scheme://foo,bar>

- - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -src line: 8269 - -. - -. -

localhost:5001/foo

-. - -error: - -

<localhost:5001/foo>

- - diff --git a/test/fixtures/commonmark/good.txt b/test/fixtures/commonmark/good.txt index cb96b72..ce47df5 100644 --- a/test/fixtures/commonmark/good.txt +++ b/test/fixtures/commonmark/good.txt @@ -6815,6 +6815,24 @@ src line: 8236

MAILTO:FOO@BAR.BAZ

. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 8248 + +. + +. +

a+b+c:d

+. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 8255 + +. + +. +

made-up-scheme://foo,bar

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 8262 @@ -6824,6 +6842,15 @@ src line: 8262

http://../

. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +src line: 8269 + +. + +. +

localhost:5001/foo

+. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src line: 8278