Skip to content

Commit 7b1ff55

Browse files
committed
Merge pull request websanova#26 from bettiolo/master
Error in handling of port for https schema
2 parents 219475f + d0db386 commit 7b1ff55

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2-
npm-debug.txt
2+
npm-debug.txt
3+
.idea/

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "url",
3-
"version": "1.8.4",
3+
"version": "1.8.5",
44
"description": "A simple, lightweight url parser for JavaScript (~1.6 Kb minified, ~0.6Kb gzipped).",
55
"main": "url.js",
66
"repository": {
@@ -16,5 +16,8 @@
1616
"grunt-contrib-qunit": "",
1717
"grunt-contrib-uglify": "",
1818
"grunt-contrib-jshint": ""
19+
},
20+
"scripts": {
21+
"prepublish": "grunt"
1922
}
2023
}

tests.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(function() {
22

33
var url = 'http://rob:abcd1234@www.domain.com/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese';
4+
var urlHttps = 'https://rob:abcd1234@www.domain.com/path/index.html?query1=test&silly=willy#test=hash&chucky=cheese';
45

56
module('url');
67

@@ -41,6 +42,11 @@ test('pass', function() {
4142

4243
test('port', function() {
4344
deepEqual( window.url( 'port', url ), '80' );
45+
deepEqual( window.url( 'port', url.toUpperCase() ), '80' );
46+
deepEqual( window.url( 'port', "http://example.com:80" ), '80' );
47+
deepEqual( window.url( 'port', urlHttps ), '443' );
48+
deepEqual( window.url( 'port', urlHttps.toUpperCase() ), '443' );
49+
deepEqual( window.url( 'port', "https://example.com:443" ), '443' );
4450
});
4551

4652
test('protocol', function() {

url.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ window.url = (function() {
2020

2121
_l.protocol=url[0];
2222
_l.hostname=host[0];
23-
_l.port=(host[1]||'80');
23+
_l.port=(host[1] || ((_l.protocol.split(':')[0].toLowerCase() === 'https') ? '443' : '80'));
2424
_l.pathname=( (url.length > 3 ? '/' : '') + url.slice(3, url.length).join('/').split('?')[0].split('#')[0]);
2525
var _p = _l.pathname;
2626

@@ -31,7 +31,7 @@ window.url = (function() {
3131
else if (arg === 'domain') { return _hs.slice(-2).join('.'); }
3232
//else if (arg === 'tld') { return _hs.slice(-1).join('.'); }
3333
else if (arg === 'sub') { return _hs.slice(0, _hs.length - 2).join('.'); }
34-
else if (arg === 'port') { return _l.port || '80'; }
34+
else if (arg === 'port') { return _l.port; }
3535
else if (arg === 'protocol') { return _l.protocol.split(':')[0]; }
3636
else if (arg === 'auth') { return _l.auth; }
3737
else if (arg === 'user') { return _l.auth.split(':')[0]; }

url.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)