New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apostrophe in Querystring Value in Firefox breaks angular #920

Closed
nickretallack opened this Issue May 1, 2012 · 5 comments

Comments

Projects
None yet
2 participants
@nickretallack

nickretallack commented May 1, 2012

Example:
http://nickretallack.com/experiments/angular/apostrophe.html#/?query=some%27thing

This is a serious bug that causes angular to stop functioning until you refresh the page. This happens any time there is an <ng-view> on the page and an apostrophe in a querystring argument. It happens in Firefox, but it does not happen in Chrome. I'm using Angular 1.0rc6. The error message it produces is below.

10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: $locationWatch; newVal: 7; oldVal: 6"],["fn: $locationWatch; newVal: 8; oldVal: 7"],["fn: $locationWatch; newVal: 9; oldVal: 8"],["fn: $locationWatch; newVal: 10; oldVal: 9"],["fn: $locationWatch; newVal: 11; oldVal: 10"]]

Source code for the example program:

<!doctype html>
<html ng-app>
  <head>
    <script src="http://code.angularjs.org/angular-1.0.0rc6.js"></script>
  </head>
  <body>
    <ng-view></ng-view>
  </body>
</html>
@nickretallack

This comment has been minimized.

Show comment
Hide comment
@nickretallack

nickretallack May 1, 2012

Btw, this is curiously similar to this bug: #904

nickretallack commented May 1, 2012

Btw, this is curiously similar to this bug: #904

@nickretallack

This comment has been minimized.

Show comment
Hide comment
@nickretallack

nickretallack May 2, 2012

Here's the problem. We're comparing location.href to a location constructed from its components. Unfortunately in Firefox the hash part of location.href is not the same as location.hash when any special characters are used. location.href is fully escape()'d, while location.hash is unescape()'d. If you have an apostrophe in your url, angular compares and assigns these values repeatedly and they never become equal.

nickretallack commented May 2, 2012

Here's the problem. We're comparing location.href to a location constructed from its components. Unfortunately in Firefox the hash part of location.href is not the same as location.hash when any special characters are used. location.href is fully escape()'d, while location.hash is unescape()'d. If you have an apostrophe in your url, angular compares and assigns these values repeatedly and they never become equal.

@nickretallack

This comment has been minimized.

Show comment
Hide comment
@nickretallack

nickretallack May 2, 2012

In Chorme, location.href does not escape apostrophes.

nickretallack commented May 2, 2012

In Chorme, location.href does not escape apostrophes.

@nickretallack

This comment has been minimized.

Show comment
Hide comment
@nickretallack

nickretallack May 2, 2012

Okay, it appears apostrophes are the only thing causing the inconsistency. Firefox escapes them and Chrome does not. escape() escapes them and encodeURIComponent and encodeURI do not. To patch up the inconsistency, modify Browser#url like so:

2915c2915,2919
<       return location.href;
---
>       return location.href.replace(/%27/g,"'")

I've filed a bug on firefox.

nickretallack commented May 2, 2012

Okay, it appears apostrophes are the only thing causing the inconsistency. Firefox escapes them and Chrome does not. escape() escapes them and encodeURIComponent and encodeURI do not. To patch up the inconsistency, modify Browser#url like so:

2915c2915,2919
<       return location.href;
---
>       return location.href.replace(/%27/g,"'")

I've filed a bug on firefox.

@ghost ghost assigned IgorMinar May 7, 2012

@IgorMinar

This comment has been minimized.

Show comment
Hide comment
@IgorMinar

IgorMinar May 7, 2012

Member

I'll look into this week. Thanks for the detailed info.

Member

IgorMinar commented May 7, 2012

I'll look into this week. Thanks for the detailed info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment