Package org.apache.tomcat.util.buf

# Class UDecoder

java.lang.Object
org.apache.tomcat.util.buf.UDecoder

public final class UDecoder extends Object
All URL decoding happens here. This way we can reuse, review, optimize without adding complexity to the buffers. The conversion will modify the original buffer.

Author:
  Costin Manolache

## Field Summary

Fields
Modifier and Type
Field
Description
`static final boolean`
`ALLOW_ENCODED_SLASH`
Deprecated.

## Constructor Summary

Constructors
Constructor
Description
`UDecoder()`

## Method Summary

Modifier and Type
Method
Description
`String`
`convert(String str, boolean query)`
Deprecated.
Unused.
`void`
`convert(ByteChunk mb, boolean query)`
URLDecode, will modify the source.
`void`
`convert(ByteChunk mb, EncodedSolidusHandling encodedSolidusHandling)`
URLDecode, will modify the source.
`void`
`convert(CharChunk mb, boolean query)`
Deprecated.
Unused.
`void`
`convert(MessageBytes mb, boolean query)`
Deprecated.
Unused.
`static String`
`URLDecode(byte[] bytes, String enc, boolean isQuery)`
Deprecated.
This method will be removed in Tomcat 9
`static String`
`URLDecode(String str)`
Deprecated.
Unused.
`static String`
`URLDecode(String str, String enc)`
Deprecated.
This method will be removed in Tomcat 9
`static String`
`URLDecode(String str, String enc, boolean isQuery)`
Deprecated.
This method will be removed in Tomcat 9
`static String`
`URLDecode(String str, Charset charset)`
Decode and return the specified URL-encoded String.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### ALLOW_ENCODED_SLASH

@Deprecated public static final boolean ALLOW_ENCODED_SLASH
Deprecated.

## Constructor Details

### UDecoder

public UDecoder()

## Method Details

### convert

public void convert(ByteChunk mb, boolean query) throws IOException
URLDecode, will modify the source. Assumes source bytes are encoded using a superset of US-ASCII as per RFC 7230. "%2f" will be rejected unless the input is a query string.

Parameters:
  `mb` - The URL encoded bytes
  `query` - `true` if this is a query string. For a query string '+' will be decoded to ' '
Throws:
  `IOException` - Invalid %xx URL encoding

### convert

public void convert(ByteChunk mb, EncodedSolidusHandling encodedSolidusHandling) throws IOException
URLDecode, will modify the source. Assumes source bytes are encoded using a superset of US-ASCII as per RFC 7230.

Parameters:
  `mb` - The URL encoded bytes
  `encodedSolidusHandling` - How should the %2f sequence handled by the decoder? For query strings this parameter will be ignored and the %2f sequence will be decoded
Throws:
  `IOException` - Invalid %xx URL encoding

### convert

@Deprecated public void convert(CharChunk mb, boolean query) throws IOException
Deprecated.
Unused. Will be removed in Tomcat 10
In-buffer processing - the buffer will be modified.

WARNING: This method assumes US-ASCII encoding.

Parameters:
  `mb` - The URL encoded chars
  `query` - `true` if this is a query string
Throws:
  `IOException` - Invalid %xx URL encoding

### convert

@Deprecated public void convert(MessageBytes mb, boolean query) throws IOException
Deprecated.
Unused. Will be removed in Tomcat 10
URLDecode, will modify the source.

WARNING: This method assumes US-ASCII encoding.

Parameters:
  `mb` - The URL encoded String, bytes or chars
  `query` - `true` if this is a query string
Throws:
  `IOException` - Invalid %xx URL encoding

### convert

@Deprecated public String convert(String str, boolean query)
Deprecated.
Unused. Will be removed in Tomcat 10
%xx decoding of a string.

WARNING: This method assumes US-ASCII encoding.

FIXME: this is inefficient.

Parameters:
  `str` - The URL encoded string
  `query` - `true` if this is a query string
Returns:
  the decoded string

### URLDecode

@Deprecated public static String URLDecode(String str)
Deprecated.
Unused. This will be removed in Tomcat 10 onwards
Decode and return the specified URL-encoded String. When the byte array is converted to a string, ISO-885901 is used. This may be different than some other servers. It is assumed the string is not a query string.

Parameters:
  `str` - The url-encoded string
Returns:
  the decoded string
Throws:
  `IllegalArgumentException` - if a '%' character is not followed by a valid 2-digit hexadecimal number

### URLDecode

@Deprecated public static String URLDecode(String str, String enc)
Deprecated.
This method will be removed in Tomcat 9
Decode and return the specified URL-encoded String. It is assumed the string is not a query string.

Parameters:
  `str` - The url-encoded string
  `enc` - The encoding to use; if null, ISO-885901 is used. If an unsupported encoding is specified null will be returned
Returns:
  the decoded string
Throws:
  `IllegalArgumentException` - if a '%' character is not followed by a valid 2-digit hexadecimal number

### URLDecode

public static String URLDecode(String str, Charset charset)
Decode and return the specified URL-encoded String. It is assumed the string is not a query string.

Parameters:
  `str` - The url-encoded string
  `charset` - The character encoding to use; if null, ISO-8859-1 is used.
Returns:
  the decoded string
Throws:
  `IllegalArgumentException` - if a '%' character is not followed by a valid 2-digit hexadecimal number

### URLDecode

@Deprecated public static String URLDecode(String str, String enc, boolean isQuery)
Deprecated.
This method will be removed in Tomcat 9
Decode and return the specified URL-encoded String.

Parameters:
  `str` - The url-encoded string
  `enc` - The encoding to use; if null, ISO-8859-1 is used. If an unsupported encoding is specified null will be returned
  `isQuery` - Is this a query string being processed
Returns:
  the decoded string
Throws:
  `IllegalArgumentException` - if a '%' character is not followed by a valid 2-digit hexadecimal number

### URLDecode

@Deprecated public static String URLDecode(byte[] bytes, String enc, boolean isQuery)
Deprecated.
This method will be removed in Tomcat 9
Decode and return the specified URL-encoded byte array.

Parameters:
  `bytes` - The url-encoded byte array
  `enc` - The encoding to use; if null, ISO-8859-1 is used. If an unsupported encoding is specified null will be returned
  `isQuery` - Is this a query string being processed
Returns:
  the decoded string
Throws:
  `IllegalArgumentException` - if a '%' character is not followed by a valid 2-digit hexadecimal number