Side navigation
#11097 closed enhancement (wontfix)
Opened December 22, 2011 07:03PM UTC
Closed December 23, 2011 01:25AM UTC
Last modified November 21, 2012 05:17PM UTC
$.param should allow custom URI encoding
Reported by: | Ramses Vidor <ramsvidor@gmail.com> | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | ajax | Version: | 1.7.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
$.paramuses the JavaScript
encodeURIComponent()function for encoding request params, which has a few issues when not encoding UTF-8 characters in AJAX requests.
One of the issues occurs when encoding ISO-8859-1 and sending an AJAX request to a Java backend using Struts 2. The backend doesn't recognise the URI encoding with this function, but works well with the JavaScript function
escape().
Instead of using the
encodeURIComponent()directly, it would be better to use a custom jQuery module, (i.e.
$.encodeURI), which could be overwritten in the cases where encodeURIComponent doesn't work properly.
Example:
Implement:
// Case 1 - doesn't affect current implementation $.fn.encodeURI = function( uri ) { return encodeURIComponent( uri ); };
And change the line 7602 (jQuery 1.7.1) to:
s[ s.length ] = jQuery.encodeURI( key ) + "=" + jQuery.encodeURI( value );
Then it could be easily overwritten to:
// Case 2 - overwritten to be compatible // with ISO-8859-1 and Java/Struts 2 backend $.fn.encodeURI = function( uri ) { return escape( uri ); };
Attachments (0)
Change History (5)
Changed December 23, 2011 01:25AM UTC by comment:1
component: | unfiled → ajax |
---|---|
priority: | undecided → low |
resolution: | → wontfix |
status: | new → closed |
Changed March 28, 2012 05:54PM UTC by comment:2
I am having the same charset issue with encodeURIComponent. How do I could change this behavior without overwriting the whole method?
Changed March 28, 2012 06:02PM UTC by comment:3
Since encodeURIComponent
is a standard JavaScript function your best bet would be to use UTF-8. Otherwise write yourself a patch or plugin. The forums would be a better bet for getting a specific solution.
Changed March 28, 2012 07:15PM UTC by comment:4
According to Mozilla:
escape():
"The escape and unescape functions do not work properly for non-ASCII characters and have been deprecated. In JavaScript 1.5 and later, use encodeURI, decodeURI, encodeURIComponent, and decodeURIComponent."
encodeURIComponent():
"Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the ''UTF-8'' encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters)."
Looks like this is why jQuery uses encodeURIComponent instead of escape. Unfortunately this kind of thing breaks old apps written with other charsets instead of UTF-8.
The suggested solution above would be nice, cause it allow you to override only the code portion that escapes the parameters. So we wouldn't need to rewrite all the jQuery.param behavior into a new plugin.
This can easily be monkey patched and offered as a plugin.