mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
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:
@@ -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/');
|
||||
|
||||
Reference in New Issue
Block a user