This project is archived and is in readonly mode.

#491 ✓invalid
Oskar Krawczyk

Sending data as a string | object causes different results

Reported by Oskar Krawczyk | January 16th, 2011 @ 09:48 AM | in 1.4.0.1 (closed)

Not sure if this behavior is intentional, but it sure looks like a bug to me:

Say we're doing a request:

new Request.JSONP({
    url: 'http://jsfiddle.net/echo/jsonp/',
    data: 'mail=test+test@test.com'
}).send();

This will send mail as test test@test.com (notice the space instead of +)

The following works as expected (+ isn't replaced with a space):

new Request.JSONP({
    url: 'http://jsfiddle.net/echo/jsonp/',
    data: {
        mail: 'test+test@test.com'
    }
}).send();

Testcase: http://jsfiddle.net/zWNjG/1/

Comments and changes to this ticket

  • Arian

    Arian January 16th, 2011 @ 10:56 AM

    • State changed from “new” to “open”
    • Tag changed from request.jsonp to querystring, request.jsonp
    • Milestone set to 1.4.0.1
    • Milestone order changed from “197538” to “0”

    I would say it is expected because in the first case you use a querystring, so you need to encode the string as a querystring, and because + will always be replaced by a space, that will happen here too.

    In the second case you send it as data and not as querystring so in that case the + is preserved.

    Notice that Request works the same way: http://jsfiddle.net/zWNjG/3/

    If you create the querystring dynamically, you probably need to use the encodeURIComponent function first to encode it as a value for a querystring.

    In case someone else has another opinion, i'll leave it open for a while.

  • JacobThornton

    JacobThornton January 17th, 2011 @ 07:13 AM

    • State changed from “open” to “invalid”

    ++ to what arian said...

    objects and elements are called with toQueryString, which is responsible for properly encoding your data, while raw strings must be assumed to have already been encoded (so as not to double encode them).

    marking as invalid.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The MooTools Extensions

People watching this ticket

Pages