Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($location): support urls with any protocol
Browse files Browse the repository at this point in the history
The url used for location parsing was quite strict and did not support
custom url schemes like "chrome-extension://". With this change the only
requirement for scheme is that it doesn't contain ":" character.
  • Loading branch information
IgorMinar committed May 14, 2012
1 parent 679cb8a commit c1533ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,
var URL_MATCH = /^([^:]+):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,
PATH_MATCH = /^([^\?#]*)?(\?([^#]*))?(#(.*))?$/,
HASH_MATCH = PATH_MATCH,
DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp': 21};
Expand Down
11 changes: 11 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,17 @@ describe('$location', function() {

expect(match[10]).toBe('?book=moby');
});


it('should parse chrome extension urls', function() {
var match = URL_MATCH.exec('chrome-extension://jjcldkdmokihdaomalanmlohibnoplog/index.html?foo#bar');

expect(match[1]).toBe('chrome-extension');
expect(match[3]).toBe('jjcldkdmokihdaomalanmlohibnoplog');
expect(match[6]).toBe('/index.html');
expect(match[8]).toBe('foo');
expect(match[10]).toBe('bar');
});
});


Expand Down

0 comments on commit c1533ef

Please sign in to comment.