#498 bug
Gabriel Aubut-Lussier

Prototype messes up the multipart boundary

Reported by Gabriel Aubut-Lussier | December 19th, 2008 @ 07:21 PM

When preparing a multipart/form-data POST with the Ajax.Request class, prototype messes up the boundary by appending '; charset=' whatever the charset is set to (defaults to utf-8). See Example 1.

In order to fix this, one has to manually set the charset inside the content-type and then disable the charset. See Example 2.

Example 1 (doesn't work) :

new Ajax.Request("http://myTestSite.com/test.php", {
    method: 'post',
    contentType: 'multipart/form-data; boundary=AaB03x',
    postBody: '--AaB03x\r\nContent-Disposition: form-data; name=\"test\"\r\n\r\ntest\r\n--AaB03x--\r\n',
    onSuccess: function(transport) {
        alert(transport.responseText);
    },
    onFailure: function(transport) {
        alert('failure');
    }
});

Example 2 (works) :

new Ajax.Request("http://myTestSite.com/test.php", {
    method: 'post',
    contentType: 'multipart/form-data; charset=UTF-8; boundary=AaB03x',
    encoding: '',
    postBody: '--AaB03x\r\nContent-Disposition: form-data; name=\"test\"\r\n\r\ntest\r\n--AaB03x--\r\n',
    onSuccess: function(transport) {
        alert(transport.responseText);
    },
    onFailure: function(transport) {
        alert('failure');
    }
});

Here is the test.php script:

<?php foreach($_POST as $key => $val) {

echo $key . ": " . $val . "<BR />";

} ?>

Comments and changes to this ticket

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:26 AM

    • Tag changed from ajax.request, charset, encoding, form-data, multipart, post to missing:tests, needs_failing_test_case, needs_patch

    [not-tagged:"needs_tests" tagged:"missing:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:28 AM

    • Tag changed from missing:tests, needs_failing_test_case, needs_patch to missing:patch, missing:tests, needs_failing_test_case

    [not-tagged:"needs_patch" tagged:"missing:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:36 AM

    • Tag changed from missing:patch, missing:tests, needs_failing_test_case to missing:patch, needs:tests, needs_failing_test_case

    [not-tagged:"missing:tests" tagged:"needs:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:37 AM

    • Tag changed from missing:patch, needs:tests, needs_failing_test_case to needs:patch, needs:tests, needs_failing_test_case

    [not-tagged:"missing:patch" tagged:"needs:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:40 AM

    • Tag changed from needs:patch, needs:tests, needs_failing_test_case to needs:failing_testcase, needs:patch, needs:tests

    [not-tagged:"needs_failing_test_case" tagged:"needs:failing_testcase" bulk edit command]

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    [responsible:none bulk edit command]

  • Tobie Langel

    Tobie Langel March 1st, 2010 @ 12:51 AM

    • State changed from “new” to “bug”
    • Tag changed from needs:failing_testcase, needs:patch, needs:tests to needs:failing_testcase, needs:patch, needs:tests, section:ajax

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Pages