mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
Added tests for URL_MATCH and fixed issue with empty path
This commit was produced by a combination of 4 commits:
- Added URL_MATCH test for basic url
- Moved two tests from $location to URL_MATCH, as they should be here
- Added test for host without "/" ending and fix the regexp to pass the test
- Added another test for matching empty abs path ("/") and fix the regexp
This commit is contained in:
parent
286d1fe434
commit
a27198d52e
2 changed files with 53 additions and 23 deletions
|
|
@ -1,4 +1,4 @@
|
|||
var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?([^\?#]+)(\?([^#]*))?(#(.*))?$/,
|
||||
var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,
|
||||
HASH_MATCH = /^([^\?]*)?(\?([^\?]*))?$/,
|
||||
DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp':21},
|
||||
EAGER = 'eager',
|
||||
|
|
@ -184,7 +184,7 @@ angularServiceInject("$location", function(browser) {
|
|||
loc.protocol = match[1];
|
||||
loc.host = match[3] || '';
|
||||
loc.port = match[5] || DEFAULT_PORTS[loc.protocol] || _null;
|
||||
loc.path = match[6];
|
||||
loc.path = match[6] || '';
|
||||
loc.search = parseKeyValue(match[8]);
|
||||
loc.hash = match[10] || '';
|
||||
|
||||
|
|
|
|||
|
|
@ -128,19 +128,6 @@ describe("service", function(){
|
|||
expect($browser.getUrl()).toEqual('http://www.angularjs.org/a/b');
|
||||
});
|
||||
|
||||
it('should parse file://', function(){
|
||||
scope.$location.update('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
|
||||
expect(scope.$location.href).toEqual("file:///Users/Shared/misko/work/angular.js/scenario/widgets.html");
|
||||
expect(scope.$location.protocol).toEqual("file");
|
||||
expect(scope.$location.host).toEqual("");
|
||||
expect(scope.$location.port).toEqual(null);
|
||||
expect(scope.$location.path).toEqual("/Users/Shared/misko/work/angular.js/scenario/widgets.html");
|
||||
expect(scope.$location.search).toEqual({});
|
||||
expect(scope.$location.hash).toEqual('');
|
||||
expect(scope.$location.hashPath).toEqual('');
|
||||
expect(scope.$location.hashSearch).toEqual({});
|
||||
});
|
||||
|
||||
it('should update hashPath and hashSearch on hash update', function(){
|
||||
scope.$location.update('http://server/#path?a=b');
|
||||
scope.$eval();
|
||||
|
|
@ -178,14 +165,6 @@ describe("service", function(){
|
|||
expect(scope.$location.hash).toEqual('');
|
||||
});
|
||||
|
||||
it("should parse url which contains - in host", function(){
|
||||
scope.$location.update('http://a-b1.c-d.09/path');
|
||||
expect(scope.$location.href).toEqual('http://a-b1.c-d.09/path');
|
||||
expect(scope.$location.protocol).toEqual('http');
|
||||
expect(scope.$location.host).toEqual('a-b1.c-d.09');
|
||||
expect(scope.$location.path).toEqual('/path');
|
||||
});
|
||||
|
||||
it('should update hash before any processing', function(){
|
||||
var scope = compile('<div>');
|
||||
var log = '';
|
||||
|
|
@ -582,4 +561,55 @@ describe("service", function(){
|
|||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('URL_MATCH', function() {
|
||||
|
||||
it('should parse basic url', function() {
|
||||
var match = URL_MATCH.exec('http://www.angularjs.org/path?search#hash?x=x');
|
||||
|
||||
expect(match[1]).toEqual('http');
|
||||
expect(match[3]).toEqual('www.angularjs.org');
|
||||
expect(match[6]).toEqual('/path');
|
||||
expect(match[8]).toEqual('search');
|
||||
expect(match[10]).toEqual('hash?x=x');
|
||||
});
|
||||
|
||||
it('should parse file://', function(){
|
||||
var match = URL_MATCH.exec('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
|
||||
|
||||
expect(match[1]).toEqual('file');
|
||||
expect(match[3]).toEqual('');
|
||||
expect(match[5]).toEqual(null);
|
||||
expect(match[6]).toEqual('/Users/Shared/misko/work/angular.js/scenario/widgets.html');
|
||||
expect(match[8]).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should parse url with "-" in host', function(){
|
||||
var match = URL_MATCH.exec('http://a-b1.c-d.09/path');
|
||||
|
||||
expect(match[1]).toEqual('http');
|
||||
expect(match[3]).toEqual('a-b1.c-d.09');
|
||||
expect(match[5]).toEqual(null);
|
||||
expect(match[6]).toEqual('/path');
|
||||
expect(match[8]).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('should parse host without "/" at the end', function() {
|
||||
var match = URL_MATCH.exec('http://host.org');
|
||||
expect(match[3]).toEqual('host.org');
|
||||
|
||||
match = URL_MATCH.exec('http://host.org#');
|
||||
expect(match[3]).toEqual('host.org');
|
||||
|
||||
match = URL_MATCH.exec('http://host.org?');
|
||||
expect(match[3]).toEqual('host.org');
|
||||
});
|
||||
|
||||
it('should match with just "/" path', function() {
|
||||
var match = URL_MATCH.exec('http://server/#?book=moby');
|
||||
|
||||
expect(match[10]).toEqual('?book=moby');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue