Package com.atlassian.confluence.util
Class HtmlUtil
java.lang.Object
com.atlassian.confluence.util.HtmlUtil
Utility class for encoding and decoding HTML and URL strings. This class and all its methods are exposed on the
Velocity context. Please be mindful not to introduce methods that could be exploited in the event of an SSTI
vulnerability.
- Since:
- 5.3
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
completeUrlEncode
(String url) Deprecated.static String
completeUrlEncode
(String url, Charset encoding) Encodes the given url for protocols which theCompleteURLEncoder
supports.static String
htmlEncode
(Object object) Encodes the given Object to be HTML safe using entity escapes.static String
htmlEncode
(String text) Encodes the given text to be HTML safe using entity escapes.static String
Encodes the given text to be HTML safe using entity escapes, and embedding non-breaking spaces in place of spaces.static String
loopedUrlDecode
(String str) Uses the character encoding as per Confluence global settings.static String
loopedUrlDecode
(String str, Charset charset) Repeatedly resolves URL-encoded sequences in a string until it remains constant.static String
reencodeURL
(String originalUrl) Deprecated.since 8.7 usereencodeURL(String, Charset)
static String
reencodeURL
(String originalUrl, Charset encoding) Attempts to handle common encoding errors in hand-edited URLs, such as failing to URL encode quotes.static String
resoluteUrlDecode
(String encodedStr, Charset charset) Variant ofURLCodec.decode(String, String)
that ignores invalid encoded sequences and continues to decode the remainder of the String.static boolean
shouldUrlDecode
(String text) Checks if the given text should contains any percent encoded characters that should be decoded.static String
Deprecated.since 8.7 useurlDecode(String, Charset)
static String
Deprecated.since 8.7 useurlDecode(String, Charset)
static String
Decodes URL percent encoded characters.static String
Deprecated.since 8.7 useurlEncode(String, Charset)
static String
Deprecated.since 8.7 useurlEncode(String, Charset)
static String
Encodes HTTP form parameter/values.
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
HtmlUtil
public HtmlUtil()
-
-
Method Details
-
htmlEncode
Encodes the given Object to be HTML safe using entity escapes. If the object is a number, returns the string it in string format If the object is a string, returns htmlEncoded string For everything else returns an empty string- Parameters:
object
- the object to encode.- Returns:
- the encoded text.
-
htmlEncode
Encodes the given text to be HTML safe using entity escapes.- Parameters:
text
- the text to encode.- Returns:
- the encoded text.
-
htmlEncodeAndReplaceSpaces
Encodes the given text to be HTML safe using entity escapes, and embedding non-breaking spaces in place of spaces.- Parameters:
text
- the text to encode.- Returns:
- the encoded text.
-
completeUrlEncode
Deprecated.since 8.7 usecompleteUrlEncode(String, Charset)
Encodes the given url for protocols which theCompleteURLEncoder
supports. To only encode HTTP form parameter/values or fragments, useurlEncode(String)
instead. Uses the character encoding as perGeneralUtil.getDefaultCharset()
.- Parameters:
url
- the entire URL to encode- Returns:
- encoded url
- Since:
- 5.3.3
-
completeUrlEncode
Encodes the given url for protocols which theCompleteURLEncoder
supports. To only encode HTTP form parameter/values or fragments, useurlEncode(String)
instead. Uses the character encoding as perGeneralUtil.getDefaultCharset()
.- Parameters:
url
- the entire URL to encode- Returns:
- encoded url
- Since:
- 8.7
-
urlEncode
Deprecated.since 8.7 useurlEncode(String, Charset)
Encodes HTTP form parameter/values, using the character encoding as perGeneralUtil.getDefaultCharset()
. To encode entire URLs, usecompleteUrlEncode(java.lang.String)
instead.- Parameters:
text
- part of the url to encode- Returns:
- encoded url
- Since:
- 5.3.3
-
urlEncode
Deprecated.since 8.7 useurlEncode(String, Charset)
Encodes HTTP form parameter/values. To encode entire URLs, usecompleteUrlEncode(java.lang.String)
instead.- Parameters:
text
- part of the url to encodeencoding
- the character encoding to use- Returns:
- encoded url
- Since:
- 5.3.3
-
urlEncode
Encodes HTTP form parameter/values. To encode entire URLs, usecompleteUrlEncode(java.lang.String)
instead.- Since:
- 8.7
-
urlDecode
Deprecated.since 8.7 useurlDecode(String, Charset)
Decodes URL percent encoded characters, using the character encoding as perGeneralUtil.getDefaultCharset()
.- Parameters:
url
- the URL to decode- Returns:
- the decoded string
-
urlDecode
Deprecated.since 8.7 useurlDecode(String, Charset)
-
urlDecode
Decodes URL percent encoded characters.- Parameters:
url
- the URL to decodeencoding
- the character encoding to use while decoding- Returns:
- the decoded string
- Since:
- 8.7
-
resoluteUrlDecode
Variant ofURLCodec.decode(String, String)
that ignores invalid encoded sequences and continues to decode the remainder of the String.Invalid sequences include those with invalid hex characters (
%GG
) and incomplete sequences (%A
). -
loopedUrlDecode
Repeatedly resolves URL-encoded sequences in a string until it remains constant. -
loopedUrlDecode
Uses the character encoding as per Confluence global settings.- See Also:
-
shouldUrlDecode
Checks if the given text should contains any percent encoded characters that should be decoded.- Parameters:
text
- the text to check- Returns:
- true, if the text should be decoded
-
reencodeURL
Deprecated.since 8.7 usereencodeURL(String, Charset)
Attempts to handle common encoding errors in hand-edited URLs, such as failing to URL encode quotes.- Parameters:
originalUrl
- the url to re-encode.- Returns:
- the re-encoded URL, or the original value if it cannot be
-
reencodeURL
Attempts to handle common encoding errors in hand-edited URLs, such as failing to URL encode quotes.- Parameters:
originalUrl
- the url to re-encode.- Returns:
- the re-encoded URL, or the original value if it cannot be
- Since:
- 8.7
-
completeUrlEncode(String, Charset)