urldecode()
The urldecode() function decodes a percent-encoded URL string using a specified character set and returns the result.
Syntax
urldecode(STR[, CHARSET])
Parameters
STR- The URL-encoded string field or value to decode.
CHARSET- (Optional) The character set to use for decoding. The default is
"utf-8". Use a name registered in the IANA Charset Registry.
Description
The urldecode() function converts percent-encoding sequences in STR (such as %20) to their corresponding characters and returns the result. It uses Java's URLDecoder.decode() method.
- If
STRisnull, the function returnsnull. - If a decoding error occurs, the original
STRvalue is returned as-is. - If an invalid character set name is specified for
CHARSET, error code90850is raised.
Error codes
| Error code | Description |
|---|---|
| 90850 | An invalid character set name was specified for CHARSET. |
Usage examples
To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.
-
Decode percent-encoding in a URI
table limit=5 WEB_APACHE_SAMPLE | eval result = urldecode(uri) | fields uri, result -
Decode a URL encoded in EUC-KR
json "{'url': '%B7%CE%B1%D7%BA%D0%BC%AE'}" | eval result = urldecode(url, "EUC-KR") | # result: "로그분석" -
Decode a space character
json "{'val': 'hello%20world'}" | eval result = urldecode(val) | # result: "hello world" -
NULL input
json "{'val': null}" | eval result = urldecode(val) | # result: null
Compatibility
The urldecode() function is available since before Sonar 4.0.