Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mime: use percent-escaping for multipart form field and file names
Until now, form field and file names where escaped using the backslash-escaping algorithm defined for multipart mails. This commit replaces this with the percent-escaping method for URLs. As this may introduce incompatibilities with server-side applications, a libcurl option CURLOPT_FORM_ESCAPE_AS_MIME is introduced to revert to legacy use of backslash-escaping. This is controlled by new cli tool option --mime-escape. New tests and documentation are provided for this feature. Reported by: Ryan Sleevi Fixes curl#7789
- Loading branch information
Showing
23 changed files
with
452 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Long: mime-escape | ||
Help: Escape multipart form field/file names with the MIME algorithm | ||
Protocols: HTTP | ||
See-also: --form | ||
Added: 7.80.0 | ||
Category: http post | ||
Example: --mime-escape --form 'field\\name=curl' 'file=@load"this' $URL | ||
--- | ||
Tells curl to escape multipart form field and file names using the | ||
backslash-escaping algorithm defined for mime mail rather than | ||
the percent-escaping used in URI. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
.\" ************************************************************************** | ||
.\" * _ _ ____ _ | ||
.\" * Project ___| | | | _ \| | | ||
.\" * / __| | | | |_) | | | ||
.\" * | (__| |_| | _ <| |___ | ||
.\" * \___|\___/|_| \_\_____| | ||
.\" * | ||
.\" * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. | ||
.\" * | ||
.\" * This software is licensed as described in the file COPYING, which | ||
.\" * you should have received as part of this distribution. The terms | ||
.\" * are also available at https://curl.se/docs/copyright.html. | ||
.\" * | ||
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell | ||
.\" * copies of the Software, and permit persons to whom the Software is | ||
.\" * furnished to do so, under the terms of the COPYING file. | ||
.\" * | ||
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
.\" * KIND, either express or implied. | ||
.\" * | ||
.\" ************************************************************************** | ||
.\" | ||
.TH CURLOPT_FORM_ESCAPE_AS_MIME 3 "14 Oct 2021" "libcurl 7.80.0" "curl_easy_setopt options" | ||
.SH NAME | ||
CURLOPT_FORM_ESCAPE_AS_MIME \- change form field/file names escaping | ||
.SH SYNOPSIS | ||
#include <curl/curl.h> | ||
|
||
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FORM_ESCAPE_AS_MIME, long onoff); | ||
.SH DESCRIPTION | ||
Set the \fIonoff\fP parameter to 1 to escape multipart form field and file | ||
names using the backslash-escaping algorithm defined for mime mail rather than | ||
the percent-escaping used in URI. | ||
|
||
As an example, consider field or file name \fIstrange\\name"kind\fP. | ||
When the containing multipart form is sent, this is normally transmitted as | ||
\fIstrange\\name%22kind\fP. When this option is set, it is sent as | ||
\fIstrange\\\\name\\"kind\fP. | ||
.SH DEFAULT | ||
0, meaning disabled. | ||
.SH PROTOCOLS | ||
HTTP | ||
.SH EXAMPLE | ||
.nf | ||
CURL *curl = curl_easy_init(); | ||
curl_mime *form = NULL; | ||
|
||
if(curl) { | ||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); | ||
curl_easy_setopt(curl, CURLOPT_FORM_ESCAPE_AS_MIME, 1L); | ||
|
||
form = curl_mime_init(curl); | ||
if(form) { | ||
curl_mimepart *part = curl_mime_addpart(form); | ||
|
||
if(part) { | ||
curl_mime_filedata(part, "strange\\\\file\\\\name"); | ||
curl_mime_name(part, "strange\\"field\\"name"); | ||
curl_easy_setopt(curl, CURLOPT_MIMEPOST, form); | ||
|
||
/* Perform the request */ | ||
curl_easy_perform(curl); | ||
} | ||
} | ||
|
||
curl_easy_cleanup(curl); | ||
curl_mime_free(mime); | ||
} | ||
.fi | ||
.SH AVAILABILITY | ||
Option added in 7.80.0. Before this version, percent-escaping was never applied. | ||
.SH RETURN VALUE | ||
Returns CURLE_OK | ||
.SH "SEE ALSO" | ||
.BR CURLOPT_MIMEPOST "(3), " CURLOPT_HTTPPOST "(3)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.