Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 11 years ago

#6834 closed bug (wontfix)

$.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)

test1.js (564 bytes) - added by xiaoyongaz 13 years ago.
qunit test the show deparam change 'ab+ba' to 'ab ba'
test.html (550 bytes) - added by xiaoyongaz 13 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 13 years ago by dmethvin

Resolution: invalid
Status: newclosed

Please reopen and attach a test case.

comment:2 Changed 13 years ago by xiaoyongaz

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 13 years ago by xiaoyongaz

Attachment: test1.js added

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

Changed 13 years ago by xiaoyongaz

Attachment: test.html added

comment:3 Changed 13 years ago by xiaoyongaz

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'.

comment:4 Changed 13 years ago by dmethvin

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?

comment:5 Changed 13 years ago by xiaoyongaz

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

comment:6 Changed 13 years ago by snover

Milestone: 1.4.3

Resetting milestone to future.

comment:7 Changed 13 years ago by snover

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).

Last edited 13 years ago by snover (previous) (diff)
Note: See TracTickets for help on using tickets.