Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions purl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]+$/;
Expand Down Expand Up @@ -245,7 +245,7 @@
};

}

purl.jQuery = function($){
if ($ != null) {
$.fn.url = function( strictMode ) {
Expand Down
14 changes: 10 additions & 4 deletions test/purl-tests.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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 protected]', function() {
expect(url.attr('query')).toBe('item=value&[email protected]');
});
}

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 protected]#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 protected]#foo'))
});