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 STR is null, the function returns null.
  • If a decoding error occurs, the original STR value is returned as-is.
  • If an invalid character set name is specified for CHARSET, error code 90850 is raised.

Error codes

Error codeDescription
90850An 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.

  1. Decode percent-encoding in a URI

    table limit=5 WEB_APACHE_SAMPLE | eval result = urldecode(uri) | fields uri, result
    
  2. Decode a URL encoded in EUC-KR

    json "{'url': '%B7%CE%B1%D7%BA%D0%BC%AE'}" | eval result = urldecode(url, "EUC-KR")
    | # result: "로그분석"
    
  3. Decode a space character

    json "{'val': 'hello%20world'}" | eval result = urldecode(val)
    | # result: "hello world"
    
  4. NULL input

    json "{'val': null}" | eval result = urldecode(val)
    | # result: null
    

Compatibility

The urldecode() function is available since before Sonar 4.0.