-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Angular terminates when parsing cookies and decodeURIComponent throws error. #9211
Comments
Created Plunker |
I do not know if this is really related to ngCookies as the error is in /src/ng/browser.js. As shown in the plunk, ngCookies is not required for this error to occur. This error is in the core angular.js. |
This appears to be a native error, which breaks the app. The cookie value is not something decodeURIComponent() can deal with (for whatever reason, because of this failure, the template never gets requested) |
Should it assume that a cookie value can be decoded using decodeURIComponent? |
I believe that would make the most sense, would it not? (I don't know really, cookies are weird, lets use localStorage instead :c) |
Seeing as the cookie value is not exclusively a URI I do not see how it would be a safe assumption to make. The original spec says no encoding is assumed, while the newer spec is still pretty vague about what can be there. The problem remains that a value that does not work with decodeURIComponent breaks the app. References: |
there's going to be some reason why we're doing it, otherwise we wouldn't be doing it! I have no idea what that reason is or was, however. It's possible that we can throw it out. |
It makes sense that Angular is doing this since some characters (= and ; for instance) cannot appear in cookie name and value, so when cookies are written using Angular, it needs to encode the name and value in order to make sure that those characters are not serialized as is (and obviously it needs to decode them when reading). The problem is that no one makes any promises that other cookie writers will also choose to use this encoding and so decoding a cookie written by someone else might result with the wrong value or even fail. |
So I think there is no good solution here and we'll end up doing something ugly no matter what. One option is to revert back to |
Created a decorator to quick fix this since it totally break angular |
Tested with v1.3.0-rc.2
As far as I can tell, when angular goes to make a web request it parses the cookies that are set on the local machine. If any cookie causes decodeURIComponent to throw an error Angular will terminate. If this happens during the routing phase the view is left blank.
Origin: /src/ng/browser.js line 327
Lib: angular.js line 4832
Plunker: http://plnkr.co/edit/ZLg6SNrCteqGRrPhThWm?p=info
To reproduce, create a cookie "anyname=%abcd", use example app below.
test.html
testtemplate.html
The text was updated successfully, but these errors were encountered: