Escapes a string so it can be safely used as a value for application/x‐www‐form‐urlencoded (HTML form submissions).
Synopsis
Declared in <absl/strings/escaping.h>
[[nodiscard]]
std::string
UrlEscapePlus(std::string_view input);
Description
Historically web browsers have also used this form of escaping for query parameters.
UrlEscapePlus() differs from UrlEscape() in that space (' ') is encoded to plus ("+") instead of "%20". According to the URI specification (RFC 3986), the correct way to escape a space anywhere in a URL (including the query string) is "%20". Using "%20" in a query parameter will work universally.
Some strict URL parsers (especially outside of web browsers/web servers) follow RFC 3986 strictly and will treat a literal '+' in the query string as a literal plus sign, rather than decoding it to a space.
Recommendation: Use UrlEscapePlus() only if you are specifically implementing or interacting with a system that strictly expects "application/x‐www‐form‐urlencoded" formatting. For general URL construction, UrlEscape() is the correct and safest choice.
Example (encoding "gift for mom & dad" as a URL query parameter):
std::string url = absl::StrFormat("https://www.google.com/search?q=%s", absl::UrlEscapePlus( "gift for mom & dad")); assert(url == "https://www.google.com/search?q=gift+for+mom+%26+dad");
Return Value
The escaped string.
|
Note
|
The return value should not be discarded. |
Parameters
Name |
Description |
input |
The URL component to escape. |
Created with MrDocs