Bug Tracker

Ticket #6834 (closed bug: wontfix)

Opened 4 years ago

Last modified 2 years ago

$.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:
Blocking: Blocked by:

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

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

Change History

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

Please reopen and attach a test case.

comment:2 Changed 4 years ago by xiaoyongaz

  • Status changed from closed to reopened
  • Resolution invalid deleted

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

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

Changed 4 years ago by xiaoyongaz

comment:3 Changed 4 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 4 years ago by dmethvin

  • Status changed from reopened to closed
  • Resolution set to invalid

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

  • Status changed from closed to reopened
  • Resolution invalid deleted

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 4 years ago by snover

  • Milestone 1.4.3 deleted

Resetting milestone to future.

comment:7 Changed 4 years ago by snover

  • Priority set to undecided
  • Status changed from reopened to closed
  • Resolution set to wontfix

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 4 years ago by snover (previous) (diff)
Note: See TracTickets for help on using tickets.