?
avatar Fedik
Fedik
22 Jan 2021

Steps to reproduce the issue

A quick pseudo code:
JS:

var data = new FormData();
data.append('foo', 'bar');

Joomla.request({
 url: 'bla/bla/request/url',
 data: data
});

PHP side:

var_dump($_POST);

Using FormData: https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects

Expected result

The dump should contain array with foo => bar

Actual result

The dump contain random string;

A reason

The reason of this bug is that Joomla.request force 'Content-Type', 'application/x-www-form-urlencoded' for all POST data:

if (!options.headers || !options.headers['Content-Type']) {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}

However the Content-Type should be multipart/form-data; boundary={boundary string}. By default browser will set it correctly unles other specified.

So we should not force application/x-www-form-urlencoded' for all POST data.

avatar Fedik Fedik - open - 22 Jan 2021
avatar joomla-cms-bot joomla-cms-bot - change - 22 Jan 2021
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 22 Jan 2021
avatar Fedik Fedik - change - 22 Jan 2021
The description was changed
avatar Fedik Fedik - edited - 22 Jan 2021
avatar Fedik Fedik - change - 22 Jan 2021
Title
Joomla.request destroying FormData submission
Joomla.request destroying FormData in POST request
avatar Fedik Fedik - edited - 22 Jan 2021
avatar dgrammatiko
dgrammatiko - comment - 22 Jan 2021

I'll say deprecate the Joomla.request and use the Native fetch.
Just for the record I think I was publicly against these (also Events) wrappers...

avatar Fedik Fedik - change - 23 Jan 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-01-23 10:37:28
Closed_By Fedik
avatar Fedik Fedik - close - 23 Jan 2021
avatar Fedik
Fedik - comment - 23 Jan 2021

pull request #32119

Add a Comment

Login with GitHub to post a comment