Skip to content

Commit

Permalink
Added check for valid ip address as domain name.
Browse files Browse the repository at this point in the history
  • Loading branch information
websanova committed Nov 22, 2013
1 parent 3d83274 commit ccc5961
Show file tree
Hide file tree
Showing 5 changed files with 9 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": "url",
"version": "1.8.5",
"version": "1.8.6",
"description": "A simple, lightweight url parser for JavaScript (~1.6 Kb minified, ~0.6Kb gzipped).",
"main": "url.js",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

module('url');

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

test('domain', function() {
deepEqual( window.url( 'domain', url ), 'domain.com' );
deepEqual( window.url( 'domain', urlIp ), '1.2.3.4' );
});

test('hostname', function() {
Expand Down
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": "1.8.5",
"version": "1.8.6",
"author": {
"name": "Websanova",
"email": "rob@websanova.com",
Expand Down
5 changes: 4 additions & 1 deletion url.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ window.url = (function() {
var _h = _l.hostname, _hs = _h.split('.'), _ps = _p.split('/');

if (arg === 'hostname') { return _h; }
else if (arg === 'domain') { return _hs.slice(-2).join('.'); }
else if (arg === 'domain') {
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; }
return _hs.slice(-2).join('.');
}
//else if (arg === 'tld') { return _hs.slice(-1).join('.'); }
else if (arg === 'sub') { return _hs.slice(0, _hs.length - 2).join('.'); }
else if (arg === 'port') { return _l.port; }
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 ccc5961

Please sign in to comment.