Skip to content

Commit ccc5961

Browse files
committed
Added check for valid ip address as domain name.
1 parent 3d83274 commit ccc5961

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "url",
3-
"version": "1.8.5",
3+
"version": "1.8.6",
44
"description": "A simple, lightweight url parser for JavaScript (~1.6 Kb minified, ~0.6Kb gzipped).",
55
"main": "url.js",
66
"repository": {

tests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

67
module('url');
78

@@ -11,6 +12,7 @@ test('url', function() {
1112

1213
test('domain', function() {
1314
deepEqual( window.url( 'domain', url ), 'domain.com' );
15+
deepEqual( window.url( 'domain', urlIp ), '1.2.3.4' );
1416
});
1517

1618
test('hostname', function() {

url.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"websanova",
77
"url"
88
],
9-
"version": "1.8.5",
9+
"version": "1.8.6",
1010
"author": {
1111
"name": "Websanova",
1212
"email": "rob@websanova.com",

url.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ window.url = (function() {
2828
var _h = _l.hostname, _hs = _h.split('.'), _ps = _p.split('/');
2929

3030
if (arg === 'hostname') { return _h; }
31-
else if (arg === 'domain') { return _hs.slice(-2).join('.'); }
31+
else if (arg === 'domain') {
32+
if (/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/.test(_h)) { return _h; }
33+
return _hs.slice(-2).join('.');
34+
}
3235
//else if (arg === 'tld') { return _hs.slice(-1).join('.'); }
3336
else if (arg === 'sub') { return _hs.slice(0, _hs.length - 2).join('.'); }
3437
else if (arg === 'port') { return _l.port; }

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)