Skip to main content

Bug Tracker

Side navigation

#6834 closed bug (wontfix)

Opened July 27, 2010 06:48PM UTC

Closed November 22, 2010 05:35AM UTC

Last modified March 13, 2012 09:44PM UTC

$.ajax doesn't uri encode a string input automatically

Reported by: xiaoyongaz Owned by:
Priority: undecided Milestone:
Component: ajax Version: 1.4.2
Keywords: ajax Cc:
Blocked by: Blocking:
Description

when I pass "ab+cd" as input, it will become "ab cd" after deparam. when "ab+cd" is used in an object such as {a:"ab+cd"}, it will be encoded by calling encodeURIComponent(key)/(value). ajax should do the same for string input.

Attachments (2)
  • test.html (0.5 KB) - added by xiaoyongaz August 18, 2010 05:27PM UTC.
  • test1.js (0.6 KB) - added by xiaoyongaz August 18, 2010 05:26PM UTC.

    qunit test the show deparam change 'ab+ba' to 'ab ba'

Change History (7)

Changed July 28, 2010 02:14AM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

Please reopen and attach a test case.

Changed August 18, 2010 04:48PM UTC by xiaoyongaz comment:2

resolution: invalid
status: closedreopened

add below js in a html file

var parms_str = "ab+ba";

var paramResult = $.param(parms_str, false);

alert(paramResult);

var deObj = $.deparam(paramResult, false);

var deObj2 = $.deparam("ab ba", false);

alert(deObj);

alert(deObj2);

you can see alert deObj shows "ab ba" instead of "ab+ba"

Changed August 18, 2010 05:29PM UTC by xiaoyongaz comment:3

actuall this might be clearer, in ajax function, jQuery does

// convert data if not already a string

if ( s.data && s.processData && typeof s.data !== "string" ) {

s.data = jQuery.param( s.data, s.traditional );

}

so string input is not encoded. then we can see in the attached test, deparam will change 'ab+ba' to 'ab ba'.

Changed August 19, 2010 12:42AM UTC by dmethvin comment:4

resolution: → invalid
status: reopenedclosed

I'm sorry but I don't understand your test case. jQuery does not have a $.deparam method and $.ajax isn't used in the test case although it is supposedly the component being reported. Is this a bug report intended for jQuery core?

Changed September 13, 2010 04:52PM UTC by xiaoyongaz comment:5

resolution: invalid
status: closedreopened

The ajax isn't used because I need to setup a server to show it and it's hard to attach the whole server stack. You just need to look at the ajax function of the jQuery code below

if ( s.data && s.processData && typeof s.data !== "string" ) {

s.data = jQuery.param( s.data, s.traditional );

}

there, you don't encode string for ajax calls, but encode string in objects, which is inconsistent

Changed November 12, 2010 02:40AM UTC by snover comment:6

milestone: 1.4.3

Resetting milestone to future.

Changed November 22, 2010 05:35AM UTC by snover comment:7

_comment0: If you pass a string to the data option of `$.ajax`, you are responsible for performing any necessary serialization/encoding of the string. jQuery will not do this for you, since not all data is transmitted as application/x-www-form-urlencoded.1290404915346916
priority: → undecided
resolution: → wontfix
status: reopenedclosed

If you pass a string to the data option of $.ajax, you are responsible for performing any necessary serialization/encoding of the string. jQuery will not do this for you; if it did, it would end up double-encoding data (or otherwise mangling non-application/x-www-form-urlencoded data).