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

Commit 74a7afc

Browse files
committed
fix($location): don't call indexOf() of undefined href attribute
Closes #7721 Closes #8681
1 parent 08cc6ed commit 74a7afc

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
@@ -811,15 +811,21 @@ describe('$location', function() {
811811
attrs = attrs ? ' ' + attrs + ' ' : '';
812812

813813
// fake the base behavior
814-
if (!relLink) {
815-
if (linkHref[0] == '/') {
816-
linkHref = 'http://host.com' + linkHref;
817-
} else if(!linkHref.match(/:\/\//)) {
818-
linkHref = 'http://host.com/base/' + linkHref;
814+
if (typeof linkHref === 'string') {
815+
if (!relLink) {
816+
if (linkHref[0] == '/') {
817+
linkHref = 'http://host.com' + linkHref;
818+
} else if(!linkHref.match(/:\/\//)) {
819+
linkHref = 'http://host.com/base/' + linkHref;
820+
}
819821
}
820822
}
821823

822-
link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0];
824+
if (linkHref) {
825+
link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0];
826+
} else {
827+
link = jqLite('<a ' + attrs + '>' + content + '</a>')[0];
828+
}
823829

824830
$provide.value('$sniffer', {history: supportHist});
825831
$locationProvider.html5Mode(html5Mode);
@@ -934,6 +940,20 @@ describe('$location', function() {
934940
});
935941

936942

943+
// Regression (gh-7721)
944+
it('should not throw when clicking anchor with no href attribute when history enabled on old browser', function() {
945+
configureService(null, true, false);
946+
inject(
947+
initBrowser(),
948+
initLocation(),
949+
function($browser) {
950+
browserTrigger(link, 'click');
951+
expectNoRewrite($browser);
952+
}
953+
);
954+
});
955+
956+
937957
it('should rewrite abs link to hashbang url when history enabled on old browser', function() {
938958
configureService('/base/link?a#b', true, false);
939959
inject(

0 commit comments

Comments
 (0)