Class Whitelist
@Deprecated public class Whitelist extends Safelist
v1.14.1, this class is deprecated in favour of Safelist. The name has
been changed with the intent of promoting more inclusive language. Safelist is a drop-in replacement, and no
further changes other than updating the name in your code are required to cleanly migrate. This class will be
removed in v1.15.1. Until that release, this class acts as a shim to maintain code compatibility
(source and binary).
For a clear rationale of the removal of this change, please see Terminology, Power, and Inclusive Language in Internet-Drafts and RFCs
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description WhitelistaddAttributes(String tag, String... attributes)Deprecated.Add a list of allowed attributes to a tag.WhitelistaddEnforcedAttribute(String tag, String attribute, String value)Deprecated.Add an enforced attribute to a tag.WhitelistaddProtocols(String tag, String attribute, String... protocols)Deprecated.Add allowed URL protocols for an element's URL attribute.WhitelistaddTags(String... tags)Deprecated.Add a list of allowed elements to a safelist.static Whitelistbasic()Deprecated.static WhitelistbasicWithImages()Deprecated.protected booleanisSafeAttribute(String tagName, Element el, Attribute attr)Deprecated.Test if the supplied attribute is allowed by this safelist for this tagprotected booleanisSafeTag(String tag)Deprecated.Test if the supplied tag is allowed by this safeliststatic Whitelistnone()Deprecated.WhitelistpreserveRelativeLinks(boolean preserve)Deprecated.Configure this Safelist to preserve relative links in an element's URL attribute, or convert them to absolute links.static Whitelistrelaxed()Deprecated.WhitelistremoveAttributes(String tag, String... attributes)Deprecated.Remove a list of allowed attributes from a tag.WhitelistremoveEnforcedAttribute(String tag, String attribute)Deprecated.Remove a previously configured enforced attribute from a tag.WhitelistremoveProtocols(String tag, String attribute, String... removeProtocols)Deprecated.Remove allowed URL protocols for an element's URL attribute.WhitelistremoveTags(String... tags)Deprecated.Remove a list of allowed elements from a safelist.static WhitelistsimpleText()Deprecated.
-
Constructor Details
-
Method Details
-
basic
Deprecated. -
basicWithImages
Deprecated. -
none
Deprecated. -
relaxed
Deprecated. -
simpleText
Deprecated. -
addTags
Deprecated.Description copied from class:SafelistAdd a list of allowed elements to a safelist. (If a tag is not allowed, it will be removed from the HTML.) -
removeTags
Deprecated.Description copied from class:SafelistRemove a list of allowed elements from a safelist. (If a tag is not allowed, it will be removed from the HTML.)- Overrides:
removeTagsin classSafelist- Parameters:
tags- tag names to disallow- Returns:
- this (for chaining)
-
addAttributes
Deprecated.Description copied from class:SafelistAdd a list of allowed attributes to a tag. (If an attribute is not allowed on an element, it will be removed.)E.g.:
addAttributes("a", "href", "class")allowshrefandclassattributes onatags.To make an attribute valid for all tags, use the pseudo tag
:all, e.g.addAttributes(":all", "class").- Overrides:
addAttributesin classSafelist- Parameters:
tag- The tag the attributes are for. The tag will be added to the allowed tag list if necessary.attributes- List of valid attributes for the tag- Returns:
- this (for chaining)
-
removeAttributes
Deprecated.Description copied from class:SafelistRemove a list of allowed attributes from a tag. (If an attribute is not allowed on an element, it will be removed.)E.g.:
removeAttributes("a", "href", "class")disallowshrefandclassattributes onatags.To make an attribute invalid for all tags, use the pseudo tag
:all, e.g.removeAttributes(":all", "class").- Overrides:
removeAttributesin classSafelist- Parameters:
tag- The tag the attributes are for.attributes- List of invalid attributes for the tag- Returns:
- this (for chaining)
-
addEnforcedAttribute
Deprecated.Description copied from class:SafelistAdd an enforced attribute to a tag. An enforced attribute will always be added to the element. If the element already has the attribute set, it will be overridden with this value.E.g.:
addEnforcedAttribute("a", "rel", "nofollow")will make allatags output as<a href="..." rel="nofollow">- Overrides:
addEnforcedAttributein classSafelist- Parameters:
tag- The tag the enforced attribute is for. The tag will be added to the allowed tag list if necessary.attribute- The attribute namevalue- The enforced attribute value- Returns:
- this (for chaining)
-
removeEnforcedAttribute
Deprecated.Description copied from class:SafelistRemove a previously configured enforced attribute from a tag.- Overrides:
removeEnforcedAttributein classSafelist- Parameters:
tag- The tag the enforced attribute is for.attribute- The attribute name- Returns:
- this (for chaining)
-
preserveRelativeLinks
Deprecated.Description copied from class:SafelistConfigure this Safelist to preserve relative links in an element's URL attribute, or convert them to absolute links. By default, this is false: URLs will be made absolute (e.g. start with an allowed protocol, like e.g.http://.Note that when handling relative links, the input document must have an appropriate
base URIset when parsing, so that the link's protocol can be confirmed. Regardless of the setting of thepreserve relative linksoption, the link must be resolvable against the base URI to an allowed protocol; otherwise the attribute will be removed.- Overrides:
preserveRelativeLinksin classSafelist- Parameters:
preserve-trueto allow relative links,false(default) to deny- Returns:
- this Safelist, for chaining.
- See Also:
Safelist.addProtocols(java.lang.String, java.lang.String, java.lang.String...)
-
addProtocols
Deprecated.Description copied from class:SafelistAdd allowed URL protocols for an element's URL attribute. This restricts the possible values of the attribute to URLs with the defined protocol.E.g.:
addProtocols("a", "href", "ftp", "http", "https")To allow a link to an in-page URL anchor (i.e.
<a href="#anchor">, add a#:
E.g.:addProtocols("a", "href", "#")- Overrides:
addProtocolsin classSafelist- Parameters:
tag- Tag the URL protocol is forattribute- Attribute nameprotocols- List of valid protocols- Returns:
- this, for chaining
-
removeProtocols
Deprecated.Description copied from class:SafelistRemove allowed URL protocols for an element's URL attribute. If you remove all protocols for an attribute, that attribute will allow any protocol.E.g.:
removeProtocols("a", "href", "ftp")- Overrides:
removeProtocolsin classSafelist- Parameters:
tag- Tag the URL protocol is forattribute- Attribute nameremoveProtocols- List of invalid protocols- Returns:
- this, for chaining
-
isSafeTag
Deprecated.Description copied from class:SafelistTest if the supplied tag is allowed by this safelist -
isSafeAttribute
Deprecated.Description copied from class:SafelistTest if the supplied attribute is allowed by this safelist for this tag- Overrides:
isSafeAttributein classSafelist- Parameters:
tagName- tag to consider allowing the attribute inel- element under test, to confirm protocolattr- attribute under test- Returns:
- true if allowed
-