diff --git a/src/ng/location.js b/src/ng/location.js
index a73063bd5473..664a9ee0b4cb 100644
--- a/src/ng/location.js
+++ b/src/ng/location.js
@@ -670,7 +670,7 @@ function $LocationProvider(){
// http://msdn.microsoft.com/en-us/library/ie/dd347148(v=vs.85).aspx
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;
if (href[0] == '/') {
// absolute path - replace old path
diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js
index 2dfca7912353..2bf6e10c2abc 100644
--- a/test/ng/locationSpec.js
+++ b/test/ng/locationSpec.js
@@ -853,15 +853,21 @@ describe('$location', function() {
attrs = attrs ? ' ' + attrs + ' ' : '';
// fake the base behavior
- if (!relLink) {
- if (linkHref[0] == '/') {
- linkHref = 'http://host.com' + linkHref;
- } else if(!linkHref.match(/:\/\//)) {
- linkHref = 'http://host.com/base/' + linkHref;
+ if (typeof linkHref === 'string') {
+ if (!relLink) {
+ if (linkHref[0] == '/') {
+ linkHref = 'http://host.com' + linkHref;
+ } else if(!linkHref.match(/:\/\//)) {
+ linkHref = 'http://host.com/base/' + linkHref;
+ }
}
}
- link = jqLite('' + content + '')[0];
+ if (linkHref) {
+ link = jqLite('' + content + '')[0];
+ } else {
+ link = jqLite('' + content + '')[0];
+ }
$provide.value('$sniffer', {history: supportHist});
$locationProvider.html5Mode(html5Mode);
@@ -976,6 +982,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() {
configureService('/base/link?a#b', true, false);
inject(