From c3ad43df22fde43c0886f5ed6450ffaa00574dcd Mon Sep 17 00:00:00 2001 From: Scott Meves Date: Fri, 18 Jul 2014 16:12:48 -0400 Subject: [PATCH] Support query params with '@' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …also update buster test suite to work with latest version of buster --- purl.js | 4 ++-- test/purl-tests.js | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/purl.js b/purl.js index b5799c6..071360b 100644 --- a/purl.js +++ b/purl.js @@ -31,7 +31,7 @@ parser = { strict : /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, //less intuitive, more accurate to the specs - loose : /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs + loose : /^(?:(?![^:@?]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@?]*):?([^:@?]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs }, isint = /^[0-9]+$/; @@ -245,7 +245,7 @@ }; } - + purl.jQuery = function($){ if ($ != null) { $.fn.url = function( strictMode ) { diff --git a/test/purl-tests.js b/test/purl-tests.js index c050a6c..64a14dd 100644 --- a/test/purl-tests.js +++ b/test/purl-tests.js @@ -1,5 +1,7 @@ buster.spec.expose(); +var expect = buster.expect; + testSuite = function(url) { it('should have a protocol of http', function() { expect(url.attr('protocol')).toBe('http'); @@ -70,19 +72,23 @@ testEmptyQueryParams = function(url) { }); }; -describe("purl in non-strict mode", function () { +testAtSymbolQueryParms = function(url) { + it('should have a querystring of item=value&email=name@example.com', function() { + expect(url.attr('query')).toBe('item=value&email=name@example.com'); + }); +} +describe("purl in non-strict mode", function () { testSuite(purl('http://allmarkedup.com/folder/dir/index.html?item=value#foo')); testEmptyQueryParams(purl('http://allmarkedup.com/folder/dir/index.html#foo')); testEmptyQueryParams(purl('http://allmarkedup.com/folder/dir/index.html?#foo')); - + testAtSymbolQueryParms(purl('http://allmarkedup.com/folder/dir/index.html?item=value&email=name@example.com#foo')) }); describe("purl in strict mode", function () { - testSuite(purl('http://allmarkedup.com/folder/dir/index.html?item=value#foo', true)); testEmptyQueryParams(purl('http://allmarkedup.com/folder/dir/index.html#foo', true)); testEmptyQueryParams(purl('http://allmarkedup.com/folder/dir/index.html?#foo', true)); - + testAtSymbolQueryParms(purl('http://allmarkedup.com/folder/dir/index.html?item=value&email=name@example.com#foo')) });