mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-05-11 11:23:42 +03:00
Fix browsable API not supporting multipart/form-data correctly
- Autodetect missing boundary parameter for Content-Type header - textarea value normalises EOL chars to \n when multipart/form-data requires \r\n
This commit is contained in:
parent
871ce34983
commit
94c37c09c5
|
@ -37,6 +37,17 @@ function doAjaxSubmit(e) {
|
|||
|
||||
if (contentType) {
|
||||
data = form.find('[data-override="content"]').val() || ''
|
||||
|
||||
if (contentType === 'multipart/form-data') {
|
||||
// We need to add a boundary parameter to the header
|
||||
var re = /^--([0-9A-Z'()+_,-./:=?]{1,70})[ \f\t\v\u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]*$/im;
|
||||
var boundary = re.exec(data);
|
||||
if (boundary !== null) {
|
||||
contentType += '; boundary="' + boundary[1] + '"';
|
||||
}
|
||||
// Fix textarea.value EOL normalisation (multipart/form-data should use CR+NL, not NL)
|
||||
data = data.replace(/\n/g, '\r\n');
|
||||
}
|
||||
} else {
|
||||
contentType = form.attr('enctype') || form.attr('encoding')
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user