set_unescape_uri
The `set_unescape_uri` directive decodes a URI component by unescaping percent-encoded characters.
Description
set_unescape_uri is used to decode a URI component that may contain percent-encoded characters, such as '%20' for spaces. It can take one or two arguments. The first argument is a variable that holds the encoded string, while the second (optional) argument specifies the destination variable that will store the unescaped result. If the second argument is not provided, the result is stored in the first variable itself. This directive is especially useful for handling user input in queries where the URI might contain special characters that need to be decoded back to their original representation. It can be used in various contexts including http, server, location, and if blocks, making it versatile for different configurations where URI parsing is essential.
Config Example
location /example {
set $escaped_arg $arg_encoded;
set_unescape_uri $decoded_arg $escaped_arg;
# Now $decoded_arg contains the unescaped value.
}If the source variable is empty or contains invalid percent-encoded characters, the result may not be valid or can lead to errors.
Ensure that the directive is used in contexts that support it, as it might not work if misused in inappropriate contexts.