From 358f0ce96ba1147d0b382216af800e53682c5ff4 Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Fri, 4 Nov 2011 13:22:18 +0100 Subject: [PATCH] url: add '.' '+' and '-' in url protocol - Based on BNF from RFC 1738 section 5. - Added tests to cover svn+ssh and some other examples --- lib/url.js | 2 +- test/simple/test-url.js | 76 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/lib/url.js b/lib/url.js index 7a28e0064b..7b4e1b397f 100644 --- a/lib/url.js +++ b/lib/url.js @@ -30,7 +30,7 @@ exports.format = urlFormat; // define these here so at least they only have to be // compiled once on the first module load. -var protocolPattern = /^([a-z0-9+]+:)/i, +var protocolPattern = /^([a-z0-9.+-]+:)/i, portPattern = /:[0-9]+$/, // RFC 2396: characters reserved for delimiting URLs. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'], diff --git a/test/simple/test-url.js b/test/simple/test-url.js index c89545d640..6a847b246d 100644 --- a/test/simple/test-url.js +++ b/test/simple/test-url.js @@ -333,6 +333,49 @@ var parseTests = { 'hash' : '#bar', 'path': '/path?search=foo' }, + 'svn+ssh://foo/bar': { + 'href': 'svn+ssh://foo/bar', + 'host': 'foo', + 'hostname': 'foo', + 'protocol': 'svn+ssh:', + 'pathname': '/bar', + 'path': '/bar', + 'slashes': true + }, + 'dash-test://foo/bar': { + 'href': 'dash-test://foo/bar', + 'host': 'foo', + 'hostname': 'foo', + 'protocol': 'dash-test:', + 'pathname': '/bar', + 'path': '/bar', + 'slashes': true + }, + 'dash-test:foo/bar': { + 'href': 'dash-test:foo/bar', + 'host': 'foo', + 'hostname': 'foo', + 'protocol': 'dash-test:', + 'pathname': '/bar', + 'path': '/bar' + }, + 'dot.test://foo/bar': { + 'href': 'dot.test://foo/bar', + 'host': 'foo', + 'hostname': 'foo', + 'protocol': 'dot.test:', + 'pathname': '/bar', + 'path': '/bar', + 'slashes': true + }, + 'dot.test:foo/bar': { + 'href': 'dot.test:foo/bar', + 'host': 'foo', + 'hostname': 'foo', + 'protocol': 'dot.test:', + 'pathname': '/bar', + 'path': '/bar' + }, // IDNA tests 'http://www.日本語.com/' : { 'href': 'http://www.xn--wgv71a119e.com/', @@ -574,6 +617,39 @@ var formatTests = { 'hostname': 'foo', 'protocol': 'http:', 'pathname': '/' + }, + 'svn+ssh://foo/bar': { + 'href': 'svn+ssh://foo/bar', + 'hostname': 'foo', + 'protocol': 'svn+ssh:', + 'pathname': '/bar', + 'slashes': true + }, + 'dash-test://foo/bar': { + 'href': 'dash-test://foo/bar', + 'hostname': 'foo', + 'protocol': 'dash-test:', + 'pathname': '/bar', + 'slashes': true + }, + 'dash-test:foo/bar': { + 'href': 'dash-test:foo/bar', + 'hostname': 'foo', + 'protocol': 'dash-test:', + 'pathname': '/bar' + }, + 'dot.test://foo/bar': { + 'href': 'dot.test://foo/bar', + 'hostname': 'foo', + 'protocol': 'dot.test:', + 'pathname': '/bar', + 'slashes': true + }, + 'dot.test:foo/bar': { + 'href': 'dot.test:foo/bar', + 'hostname': 'foo', + 'protocol': 'dot.test:', + 'pathname': '/bar' } }; for (var u in formatTests) {