diff --git a/src/lib/URI.js b/src/lib/URI.js index a2591f8..cca2d4e 100644 --- a/src/lib/URI.js +++ b/src/lib/URI.js @@ -185,6 +185,10 @@ JX.install('URI', { } str += this.getDomain() || ''; + if (this.getPort()) { + str += ':' + this.getPort(); + } + // If there is a domain or a protocol, we need to provide '/' for the // path. If we don't have either and also don't have a path, we can omit // it to produce a partial URI without path information which begins diff --git a/src/lib/__tests__/URI.js b/src/lib/__tests__/URI.js index 26bbc64..3dbaa3f 100644 --- a/src/lib/__tests__/URI.js +++ b/src/lib/__tests__/URI.js @@ -4,9 +4,10 @@ describe('Javelin URI', function() { it('should understand parts of a uri', function() { - var uri = JX.$U('http://www.facebook.com/home.php?key=value#fragment'); + var uri = JX.$U('http://www.facebook.com:123/home.php?key=value#fragment'); expect(uri.getProtocol()).toEqual('http'); expect(uri.getDomain()).toEqual('www.facebook.com'); + expect(uri.getPort()).toEqual('123'); expect(uri.getPath()).toEqual('/home.php'); expect(uri.getQueryParams()).toEqual({'key' : 'value'}); expect(uri.getFragment()).toEqual('fragment');