Alexander
Alexander

Reputation: 20234

encodeURI and Ext.urlDecode

I have a page that loads some other page in an iframe via ExtJS:

alert(UNID); // returns  ...AAA==
...
    autoEl:{
        tag:"iframe",
        src: someurl+'?anyparam=anything&unid='+encodeURI(UNID)+'&someparam='
        // Chrome Console (Network tab) tells me the URI is ...AAA==&someparam=
    }

and the other web site uses ExtJS to decode the given params.

var params = Ext.urlDecode(window.location.search);
alert(params.unid); // returns ...AAA

Where is my error? If there is none, is this a bug in encodeURI or urlDecode?

Upvotes: 2

Views: 2889

Answers (1)

Emissary
Emissary

Reputation: 10148

No it's not a bug, encodeURI is not encoding the equals = symbol so when Ext.urlDecode parses the string it treats it as part of the URI - ...AAA = '' and '' = '' // useless / discarded.

The answer is simply to use the correct function when encoding a "component" part of the URI:

encodeURI('...AAA==');           // "...AAA=="
encodeURIComponent('...AAA==');  // "...AAA%3D%3D"

The differences are detailed in the documentation.

Upvotes: 2

Related Questions