Skip to content

Commit

Permalink
Add support for hashbangs (ignore).
Browse files Browse the repository at this point in the history
  • Loading branch information
websanova committed Mar 10, 2016
1 parent 573b548 commit b6fa3dc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-url",
"version": "2.2.1",
"version": "2.3.0",
"description": "A simple, lightweight url parser for JavaScript (~1.7 Kb minified, ~0.7Kb gzipped).",
"main": "url.js",
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ test('hash string', function() {
deepEqual( window.url( '#', 'http://domain.com#field[0]=zero&field[1]=one&var=test' ), {'field': ['zero', 'one'], 'var': 'test'} );
});

test('hash bangs', function() {
deepEqual( window.url( '?poo', 'http://domain.com/#!?' ), undefined );
deepEqual( window.url( '?poo', 'http://domain.com/#!/' ), undefined );
deepEqual( window.url( '-1', 'http://www.domain.com/#!/first/second/?test=foo' ), 'second' );
deepEqual( window.url( '?', 'http://domain.com/#!/?field[0]=zero&field[1]=one&var=test' ), {'field': ['zero', 'one'], 'var': 'test'} );
deepEqual( window.url( '?', 'http://domain.com/#!?field[0]=zero&field[1]=one&var=test' ), {'field': ['zero', 'one'], 'var': 'test'} );
deepEqual( window.url( '#', 'http://domain.com/#!/#field[0]=zero&field[1]=one&var=test' ), {'field': ['zero', 'one'], 'var': 'test'} );
});

if (window.url('tld?')) {
test('tld', function() {
deepEqual( window.url( 'tld', 'www.example.ly' ), 'ly' );
Expand Down
2 changes: 1 addition & 1 deletion url-tld.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion url.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"websanova",
"url"
],
"version": "2.2.1",
"version": "2.3.0",
"author": {
"name": "Websanova",
"email": "[email protected]",
Expand Down
5 changes: 5 additions & 0 deletions url.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ window.url = (function() {
}
else {

// Ignore Hashbangs.
if (tmp = url.match(/(.*?)\/#\!(.*)/)) {
url = tmp[1] + tmp[2];
}

// Hash.
if (tmp = url.match(/(.*?)#(.*)/)) {
_l.hash = tmp[2];
Expand Down
2 changes: 1 addition & 1 deletion url.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b6fa3dc

Please sign in to comment.