fix($location): don't call indexOf() of undefined href attribute
Closes #7721 Closes #8681
This commit is contained in:
+1
-1
@@ -670,7 +670,7 @@ function $LocationProvider(){
|
|||||||
// http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
|
||||||
var href = elm.attr('href') || elm.attr('xlink:href');
|
var href = elm.attr('href') || elm.attr('xlink:href');
|
||||||
|
|
||||||
if (href.indexOf('://') < 0) { // Ignore absolute URLs
|
if (href && href.indexOf('://') < 0) { // Ignore absolute URLs
|
||||||
var prefix = '#' + hashPrefix;
|
var prefix = '#' + hashPrefix;
|
||||||
if (href[0] == '/') {
|
if (href[0] == '/') {
|
||||||
// absolute path - replace old path
|
// absolute path - replace old path
|
||||||
|
|||||||
+26
-6
@@ -811,15 +811,21 @@ describe('$location', function() {
|
|||||||
attrs = attrs ? ' ' + attrs + ' ' : '';
|
attrs = attrs ? ' ' + attrs + ' ' : '';
|
||||||
|
|
||||||
// fake the base behavior
|
// fake the base behavior
|
||||||
if (!relLink) {
|
if (typeof linkHref === 'string') {
|
||||||
if (linkHref[0] == '/') {
|
if (!relLink) {
|
||||||
linkHref = 'http://host.com' + linkHref;
|
if (linkHref[0] == '/') {
|
||||||
} else if(!linkHref.match(/:\/\//)) {
|
linkHref = 'http://host.com' + linkHref;
|
||||||
linkHref = 'http://host.com/base/' + linkHref;
|
} else if(!linkHref.match(/:\/\//)) {
|
||||||
|
linkHref = 'http://host.com/base/' + linkHref;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0];
|
if (linkHref) {
|
||||||
|
link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0];
|
||||||
|
} else {
|
||||||
|
link = jqLite('<a ' + attrs + '>' + content + '</a>')[0];
|
||||||
|
}
|
||||||
|
|
||||||
$provide.value('$sniffer', {history: supportHist});
|
$provide.value('$sniffer', {history: supportHist});
|
||||||
$locationProvider.html5Mode(html5Mode);
|
$locationProvider.html5Mode(html5Mode);
|
||||||
@@ -934,6 +940,20 @@ describe('$location', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Regression (gh-7721)
|
||||||
|
it('should not throw when clicking anchor with no href attribute when history enabled on old browser', function() {
|
||||||
|
configureService(null, true, false);
|
||||||
|
inject(
|
||||||
|
initBrowser(),
|
||||||
|
initLocation(),
|
||||||
|
function($browser) {
|
||||||
|
browserTrigger(link, 'click');
|
||||||
|
expectNoRewrite($browser);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should rewrite abs link to hashbang url when history enabled on old browser', function() {
|
it('should rewrite abs link to hashbang url when history enabled on old browser', function() {
|
||||||
configureService('/base/link?a#b', true, false);
|
configureService('/base/link?a#b', true, false);
|
||||||
inject(
|
inject(
|
||||||
|
|||||||
Reference in New Issue
Block a user