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

URIError: URI malformed #13165

Closed
flyher opened this issue Oct 26, 2015 · 6 comments
Closed

URIError: URI malformed #13165

flyher opened this issue Oct 26, 2015 · 6 comments

Comments

@flyher
Copy link

flyher commented Oct 26, 2015

The web project has a cookie and it contain '%' , i use the cookie in server .but the web show me the bug.
i try to delete this cookie,and it work well.
here is the log.

URIError: URI malformed
    at decodeURIComponent (native)
    at af.h.cookies (http://open.xxx.com/common/js/lib/angular.min.js:42:362)
    at t (http://open.xxx.com/common/js/lib/angular.min.js:78:442)
    at f (http://open.xxx.com/common/js/lib/angular.min.js:76:308)
    at http://open.xxx.com/common/js/lib/angular.min.js:106:349
    at k.$eval (http://open.xxx.com/common/js/lib/angular.min.js:120:444)
    at k.$digest (http://open.xxx.com/common/js/lib/angular.min.js:118:9)
    at k.$apply (http://open.xxx.com/common/js/lib/angular.min.js:121:264)
    at http://open.xxx.com/common/js/lib/angular.min.js:18:101
    at Object.e [as invoke] (http://open.xxx.com/common/js/lib/angular.min.js:36:215)

It seems that the cookie contain '%' will cause error,is it an bug?
[ AngularJS v1.3.0-rc.3 ]

update:
it seems angularjs use 'decodeURIComponent' to decode parameter ,but 'escape' encode parameter cannot be decode,and will cause bug.
#6836
#6326

https://stackoverflow.com/questions/9064536/javascript-decodeuricomponent-malformed-uri-exception

@Narretz
Copy link
Contributor

Narretz commented Oct 28, 2015

Have you tried this with the latest version, 1.4.7?

@flyher
Copy link
Author

flyher commented Oct 29, 2015

@Narretz
Hi,i test the latest version, 1.4.7 , the bug was fixed.

then i search the code , and find function:'escape' was used in this version.
thank you for your good work!

@Narretz
Copy link
Contributor

Narretz commented Oct 29, 2015

Great stuff, thanks for checking,

@Narretz Narretz closed this as completed Oct 29, 2015
@hamzazaidi
Copy link

I came across the same problem recently, i am on angular 1.5.3 and if the URL contain '%' angular is throwing the following error.

angular.js:12324 Uncaught URIError: URI malformed
at decodeURIComponent ()
at parseAppUrl (http://xxxxxx/js/angular.js:12324:24)
at LocationHtml5Url.$$parse (http://xxxxxx/js/angular.js:12394:5)
at LocationHtml5Url.$$parseLinkUrl (http://xxxxxx/js/angular.js:12438:12)
at $LocationProvider.$get (http://xxxxxx/js/angular.js:13112:15)
at Object.invoke (http://xxxxxx/js/angular.js:4625:19)
at http://xxxxxx/js/angular.js:4424:37
at getService (http://xxxxxx/js/angular.js:4571:39)
at injectionArgs (http://xxxxxx/js/angular.js:4595:58)
at Object.invoke (http://xxxxxx/js/angular.js:4617:18)

@gkalpak
Copy link
Member

gkalpak commented Nov 8, 2016

According to the spec, % has a special meaning in URLs and is used for escaping (e.g. %<hex><hex>).
If they are used incorrectly in URLs, then is it expected that the native decodeURIComponent() (which Angular relies on) will throw an error. If you want a % to appear in the URL, you need to encode it.

@hamzazaidi , if you still believe that this is a bug in Angular, please open a new issue providing the necessary details to reproduce the problem (ideally a runnable demo, using CodePen, Plnkr etc).

@flyher
Copy link
Author

flyher commented Nov 9, 2016

@hamzazaidi
Hi,
there have many methods to avoid the %.
use ajax to refresh page replace use % in url , or you can use escape/encodeURIComponent/encodeURI to encode the url.
The problem is if you use escape, you need use unescape to decode it.

escape -> unescape
encodeURI -> decodeURI
encodeURIComponent -> decodeURIComponent

Try to use another method to decode/encode string.

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