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

Commit 5b77e30

Browse files
committed
fix($location): don't call indexOf() of undefined href attribute
Closes #7721 Closes #8681
1 parent b7e82a3 commit 5b77e30

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ function $LocationProvider(){
670670
// http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
671671
var href = elm.attr('href') || elm.attr('xlink:href');
672672

673-
if (href.indexOf('://') < 0) { // Ignore absolute URLs
673+
if (href && href.indexOf('://') < 0) { // Ignore absolute URLs
674674
var prefix = '#' + hashPrefix;
675675
if (href[0] == '/') {
676676
// absolute path - replace old path

test/ng/locationSpec.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -853,15 +853,21 @@ describe('$location', function() {
853853
attrs = attrs ? ' ' + attrs + ' ' : '';
854854

855855
// fake the base behavior
856-
if (!relLink) {
857-
if (linkHref[0] == '/') {
858-
linkHref = 'http://host.com' + linkHref;
859-
} else if(!linkHref.match(/:\/\//)) {
860-
linkHref = 'http://host.com/base/' + linkHref;
856+
if (typeof linkHref === 'string') {
857+
if (!relLink) {
858+
if (linkHref[0] == '/') {
859+
linkHref = 'http://host.com' + linkHref;
860+
} else if(!linkHref.match(/:\/\//)) {
861+
linkHref = 'http://host.com/base/' + linkHref;
862+
}
861863
}
862864
}
863865

864-
link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0];
866+
if (linkHref) {
867+
link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0];
868+
} else {
869+
link = jqLite('<a ' + attrs + '>' + content + '</a>')[0];
870+
}
865871

866872
$provide.value('$sniffer', {history: supportHist});
867873
$locationProvider.html5Mode(html5Mode);
@@ -976,6 +982,20 @@ describe('$location', function() {
976982
});
977983

978984

985+
// Regression (gh-7721)
986+
it('should not throw when clicking anchor with no href attribute when history enabled on old browser', function() {
987+
configureService(null, true, false);
988+
inject(
989+
initBrowser(),
990+
initLocation(),
991+
function($browser) {
992+
browserTrigger(link, 'click');
993+
expectNoRewrite($browser);
994+
}
995+
);
996+
});
997+
998+
979999
it('should rewrite abs link to hashbang url when history enabled on old browser', function() {
9801000
configureService('/base/link?a#b', true, false);
9811001
inject(

0 commit comments

Comments
 (0)