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

html5 mode with mismatching base href causes "TypeError: Cannot read property 'replace' of undefined" error in location.js #13565

Closed
jamlee1 opened this issue Dec 17, 2015 · 4 comments

Comments

@jamlee1
Copy link

jamlee1 commented Dec 17, 2015

Looking at the latest version of location.js (https://github.com/angular/angular.js/blob/4412fe238f37f79a2017ee7b20ba089c0acd73e9/src/ng/location.js)

If the tag does not match the actual href, $$parseLinkUrl will miss all the conditions and rewrittenUrl will not be defined, which means this.$$parse will not be called and $$absUrl will not be set.

Later on line 902 (

if (trimEmptyHash($location.absUrl()) != trimEmptyHash(initialUrl)) {
), trimEmptyHash($location.absUrl()) will be called in a condition, which will end up having trimEmptyHash call .replace on undefined, so we end up halting with:

TypeError: Cannot read property 'replace' of undefined

@Narretz
Copy link
Contributor

Narretz commented Dec 17, 2015

I'm not sure I understand the problem. In what case would the base tag not match the actual href?

@jamlee1
Copy link
Author

jamlee1 commented Jan 4, 2016

In my case, the html was being served on multiple domains. Granted, we can correct that base url, but it still shouldn't cause a javascript error in angular.

@OverZealous
Copy link

I agree, this shouldn't cause an unknown error. This is happening to us, and we couldn't see it until production, and it simply killed the page. Having such a low-level JS error seems like something that should have feedback.

(It was a weird case in our situation, too, a production-only url rewrite that triggered an error.)

@gkalpak
Copy link
Member

gkalpak commented Jun 3, 2016

Should be fixed by #14488.

@gkalpak gkalpak modified the milestones: Backlog, Purgatory Jun 3, 2016
@gkalpak gkalpak closed this as completed in b9ac336 Jun 6, 2016
gkalpak pushed a commit that referenced this issue Jun 6, 2016
Initialize `$$absUrl` to an empty string, in order to avoid exception, when base href
and current location have different domains.

Fixes #11091
Fixes #13565

Closes #14488
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants