Skip to content

Commit

Permalink
Fix to not remove trailing slash on paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
websanova committed Apr 22, 2017
1 parent daeed5e commit 6d1209c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 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.4.1",
"version": "2.5.0",
"description": "A simple, lightweight url parser for JavaScript (~1.7 Kb minified, ~0.7Kb gzipped).",
"main": "url.js",
"repository": {
Expand Down
26 changes: 14 additions & 12 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,25 @@ test('protocol', function() {
test('path', function() {
deepEqual( window.url( 'path', url ), '/path/index.html' );
deepEqual( window.url( 'path', 'http://www.domain.com/first/second' ), '/first/second' );
deepEqual( window.url( 'path', 'http://www.domain.com/first/second/' ), '/first/second' );
deepEqual( window.url( 'path', 'http://www.domain.com/first/second/' ), '/first/second/' );
deepEqual( window.url( 'path', 'http://www.domain.com:8080/first/second' ), '/first/second' );
deepEqual( window.url( 'path', 'http://www.domain.com:8080/first/second/' ), '/first/second' );
deepEqual( window.url( 'path', 'http://www.domain.com:8080/first/second/' ), '/first/second/' );
deepEqual( window.url( 'path', 'http://www.domain.com/first/second?test=foo' ), '/first/second' );
deepEqual( window.url( 'path', 'http://www.domain.com/first/second/?test=foo' ), '/first/second' );
deepEqual( window.url( 'path', 'http://www.domain.com/first/second/?test=foo' ), '/first/second/' );
deepEqual( window.url( 'path', 'http://www.domain.com/path#anchor' ), '/path' );
deepEqual( window.url( 'path', 'http://www.domain.com/path/#anchor' ), '/path' );
deepEqual( window.url( 'path', 'http://www.domain.com/path/#anchor' ), '/path/' );
deepEqual( window.url( 'path', 'http://www.domain.com' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com/' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com/' ), '/' );
deepEqual( window.url( 'path', 'http://www.domain.com#anchor' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com/#anchor' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com/#anchor' ), '/' );
deepEqual( window.url( 'path', 'http://www.domain.com?test=foo' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com/?test=foo' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com/?test=foo' ), '/' );
deepEqual( window.url( 'path', 'http://www.domain.com:80' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com:80/' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com:80/' ), '/' );
deepEqual( window.url( 'path', 'http://www.domain.com:80#anchor' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com:80/#anchor' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com:80/#anchor' ), '/' );
deepEqual( window.url( 'path', 'http://www.domain.com:80?test=foo' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com:80/?test=foo' ), '' );
deepEqual( window.url( 'path', 'http://www.domain.com:80/?test=foo' ), '/' );
});

test('file', function() {
Expand All @@ -186,7 +186,8 @@ test('url parts', function() {
deepEqual( window.url( '1', 'http://www.domain.com/first/second' ), 'first' );
deepEqual( window.url( '1', 'http://www.domain.com/first/second/' ), 'first' );
deepEqual( window.url( '-1', 'http://www.domain.com/first/second?test=foo' ), 'second' );
deepEqual( window.url( '-1', 'http://www.domain.com/first/second/?test=foo' ), 'second' );
deepEqual( window.url( '-1', 'http://www.domain.com/first/second/?test=foo' ), '' );
deepEqual( window.url( '-2', 'http://www.domain.com/first/second/?test=foo' ), 'second' );
});

test('query string', function() {
Expand Down Expand Up @@ -238,7 +239,8 @@ test('hash string', function() {
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( '-1', 'http://www.domain.com/#!/first/second/?test=foo' ), '' );
deepEqual( window.url( '-2', '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'} );
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.4.1",
"version": "2.5.0",
"author": {
"name": "Websanova",
"email": "rob@websanova.com",
Expand Down
2 changes: 1 addition & 1 deletion url.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
}

// Clean up path.
_l.path = (_l.path || '').replace(/^([^\/])/, '/$1').replace(/\/$/, '');
_l.path = (_l.path || '').replace(/^([^\/])/, '/$1');

// Return path parts.
if (arg.match(/^[\-0-9]+$/)) { arg = arg.replace(/^([^\/])/, '/$1'); }
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 6d1209c

Please sign in to comment.