Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URI.regex | Added IPv6 compatibility #1322

Merged
merged 3 commits into from Sep 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Types/URI.js
Expand Up @@ -39,7 +39,7 @@ var URI = this.URI = new Class({
/*base: false*/
},

regex: /^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)?(\.\.?$|(?:[^?#\/]*\/)*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
regex: /^(?:(\w+):)?(?:\/\/(?:(?:([^:@\/]*):?([^:@\/]*))?@)?(\[[A-Fa-f0-9:]+\]|[^:\/?#]*)(?::(\d*))?)?(\.\.?$|(?:[^?#\/]*\/)*)([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
parts: ['scheme', 'user', 'password', 'host', 'port', 'directory', 'file', 'query', 'fragment'],
schemes: {http: 80, https: 443, ftp: 21, rtsp: 554, mms: 1755, file: 0},

Expand Down
36 changes: 31 additions & 5 deletions Specs/Types/URI.js
Expand Up @@ -132,25 +132,25 @@ provides: [URI.Tests]

});

describe("URI merging", function () {
describe("URI merging", function(){

var myURI;
beforeEach(function () {
beforeEach(function(){
myURI = new URI('http://user:password@www.test.com:8383/the/path.html?param=value&animal=cat#car=ferrari');
});

it("should retrieve the 'fragment' part", function () {
it("should retrieve the 'fragment' part", function(){
expect(myURI.get('fragment')).toEqual('car=ferrari');
});

it("should insert new data into 'fragment'", function () {
it("should insert new data into 'fragment'", function(){
myURI.setData({
color: 'blue'
}, true, 'fragment')
expect(myURI.get('fragment')).toEqual('car=ferrari&color=blue');
});

it("should merge values from setData into URI overriding old keys with new value", function () {
it("should merge values from setData into URI overriding old keys with new value", function(){

var inicialQuery = myURI.get('query');
expect(inicialQuery).toEqual('param=value&animal=cat');
Expand All @@ -165,4 +165,30 @@ provides: [URI.Tests]
});
});

describe('URI ipv6', function(){
var suite = [
["http://10.0.0.1/", "10.0.0.1"],
["http://192.168.0.4/foo?bar#baz", "192.168.0.4"],
["http://192.168.0.4:60/foo?bar#baz", "192.168.0.4"],
["http://foo@192.168.0.4/foo?bar#baz", "192.168.0.4"],
["http://foo:bar@192.168.0.4/foo?bar#baz", "192.168.0.4"],
["http://foo:bar@192.168.0.4:8080/foo?bar#baz", "192.168.0.4"],
["http://foo:bar@[::1]:8080/foo?bar#baz", "[::1]"],
["http://foo:bar@[FE80::0202:B3FF:FE1E:8329]:8080/foo?bar#baz", "[FE80::0202:B3FF:FE1E:8329]"],
["http://foo:bar@[2001:db8::1]:8080/foo?bar#baz", "[2001:db8::1]"]
];

suite.each(function(test){
it('resolve uri properly', function(){
var uri = test[0];
var control = test[1];
var url = new URI(uri);
var res = url.toString();
var resHost = url.get('host');
expect(resHost).toBe(control);
expect(res).toBe(uri);
});
});
});

})();