diff --git a/package.json b/package.json index f5ed845..8bd48cd 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/tests.js b/tests.js index 9452450..600c530 100644 --- a/tests.js +++ b/tests.js @@ -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() { @@ -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() { @@ -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'} ); diff --git a/url-tld.min.js b/url-tld.min.js index 285a647..32f3142 100644 --- a/url-tld.min.js +++ b/url-tld.min.js @@ -1 +1 @@ -/*! js-url - v2.4.0 - 2017-02-13 */!function(){var a=function(){function a(){return new RegExp(/(.*?)\.?([^\.]*?)\.?(com|net|org|biz|ws|in|me|co\.uk|co|org\.uk|ltd\.uk|plc\.uk|me\.uk|edu|mil|br\.com|cn\.com|eu\.com|hu\.com|no\.com|qc\.com|sa\.com|se\.com|se\.net|us\.com|uy\.com|ac|co\.ac|gv\.ac|or\.ac|ac\.ac|af|am|as|at|ac\.at|co\.at|gv\.at|or\.at|asn\.au|com\.au|edu\.au|org\.au|net\.au|id\.au|be|ac\.be|adm\.br|adv\.br|am\.br|arq\.br|art\.br|bio\.br|cng\.br|cnt\.br|com\.br|ecn\.br|eng\.br|esp\.br|etc\.br|eti\.br|fm\.br|fot\.br|fst\.br|g12\.br|gov\.br|ind\.br|inf\.br|jor\.br|lel\.br|med\.br|mil\.br|net\.br|nom\.br|ntr\.br|odo\.br|org\.br|ppg\.br|pro\.br|psc\.br|psi\.br|rec\.br|slg\.br|tmp\.br|tur\.br|tv\.br|vet\.br|zlg\.br|br|ab\.ca|bc\.ca|mb\.ca|nb\.ca|nf\.ca|ns\.ca|nt\.ca|on\.ca|pe\.ca|qc\.ca|sk\.ca|yk\.ca|ca|cc|ac\.cn|com\.cn|edu\.cn|gov\.cn|org\.cn|bj\.cn|sh\.cn|tj\.cn|cq\.cn|he\.cn|nm\.cn|ln\.cn|jl\.cn|hl\.cn|js\.cn|zj\.cn|ah\.cn|gd\.cn|gx\.cn|hi\.cn|sc\.cn|gz\.cn|yn\.cn|xz\.cn|sn\.cn|gs\.cn|qh\.cn|nx\.cn|xj\.cn|tw\.cn|hk\.cn|mo\.cn|cn|cx|cz|de|dk|fo|com\.ec|tm\.fr|com\.fr|asso\.fr|presse\.fr|fr|gf|gs|co\.il|net\.il|ac\.il|k12\.il|gov\.il|muni\.il|ac\.in|co\.in|org\.in|ernet\.in|gov\.in|net\.in|res\.in|is|it|ac\.jp|co\.jp|go\.jp|or\.jp|ne\.jp|ac\.kr|co\.kr|go\.kr|ne\.kr|nm\.kr|or\.kr|li|lt|lu|asso\.mc|tm\.mc|com\.mm|org\.mm|net\.mm|edu\.mm|gov\.mm|ms|nl|no|nu|pl|ro|org\.ro|store\.ro|tm\.ro|firm\.ro|www\.ro|arts\.ro|rec\.ro|info\.ro|nom\.ro|nt\.ro|se|si|com\.sg|org\.sg|net\.sg|gov\.sg|sk|st|tf|ac\.th|co\.th|go\.th|mi\.th|net\.th|or\.th|tm|to|com\.tr|edu\.tr|gov\.tr|k12\.tr|net\.tr|org\.tr|com\.tw|org\.tw|net\.tw|ac\.uk|uk\.com|uk\.net|gb\.com|gb\.net|vg|sh|kz|ch|info|ua|gov|name|pro|ie|hk|com\.hk|org\.hk|net\.hk|edu\.hk|us|tk|cd|by|ad|lv|eu\.lv|bz|es|jp|cl|ag|mobi|eu|co\.nz|org\.nz|net\.nz|maori\.nz|iwi\.nz|io|la|md|sc|sg|vc|tw|travel|my|se|tv|pt|com\.pt|edu\.pt|asia|fi|com\.ve|net\.ve|fi|org\.ve|web\.ve|info\.ve|co\.ve|tel|im|gr|ru|net\.ru|org\.ru|hr|com\.hr|ly|xyz)$/)}function b(a){return decodeURIComponent(a.replace(/\+/g," "))}function c(a,b){var c=a.charAt(0),d=b.split(c);return c===a?d:(a=parseInt(a.substring(1),10),d[a<0?d.length+a:a-1])}function d(a,c){for(var d=a.charAt(0),e=c.split("&"),f=[],g={},h=[],i=a.substring(1),j=0,k=e.length;j