fix(urlUtils): urlUtils doesn't return right path for file:// on win

Chrome and other browsers on Windows often
append the drive name to the pathname,
as described in #4680. This would cause
the location service to browse to odd
URLs, such as /C:/myfile.html,
when opening apps using file://.

Fixes  #4680
This commit is contained in:
ROUL
2013-11-10 02:25:33 +01:00
committed by Jeff Cross
parent e1254b266d
commit f925e8caa6
2 changed files with 78 additions and 5 deletions

View File

@@ -10,6 +10,49 @@ describe('$location', function() {
jqLite(document).off('click');
});
describe('File Protocol', function () {
var urlParsingNodePlaceholder;
beforeEach(inject(function ($sniffer) {
if ($sniffer.msie) return;
urlParsingNodePlaceholder = urlParsingNode;
//temporarily overriding the DOM element
//with output from IE, if not in IE
urlParsingNode = {
hash : "#/C:/",
host : "",
hostname : "",
href : "file:///C:/base#!/C:/foo",
pathname : "/C:/foo",
port : "",
protocol : "file:",
search : "",
setAttribute: angular.noop
};
}));
afterEach(inject(function ($sniffer) {
if ($sniffer.msie) return;
//reset urlParsingNode
urlParsingNode = urlParsingNodePlaceholder;
expect(urlParsingNode.pathname).not.toBe('/C:/foo');
}));
it('should not include the drive name in path() on WIN', function (){
//See issue #4680 for details
url = new LocationHashbangUrl('file:///base', '#!');
url.$$parse('file:///base#!/foo?a=b&c#hash');
expect(url.path()).toBe('/foo');
});
});
describe('NewUrl', function() {
beforeEach(function() {
url = new LocationHtml5Url('http://www.domain.com:9877/');