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 Whitelist
addAttributes(String tag, String... attributes)
Deprecated.Add a list of allowed attributes to a tag.Whitelist
addEnforcedAttribute(String tag, String attribute, String value)
Deprecated.Add an enforced attribute to a tag.Whitelist
addProtocols(String tag, String attribute, String... protocols)
Deprecated.Add allowed URL protocols for an element's URL attribute.Whitelist
addTags(String... tags)
Deprecated.Add a list of allowed elements to a safelist.static Whitelist
basic()
Deprecated.static Whitelist
basicWithImages()
Deprecated.protected boolean
isSafeAttribute(String tagName, Element el, Attribute attr)
Deprecated.Test if the supplied attribute is allowed by this safelist for this tagprotected boolean
isSafeTag(String tag)
Deprecated.Test if the supplied tag is allowed by this safeliststatic Whitelist
none()
Deprecated.Whitelist
preserveRelativeLinks(boolean preserve)
Deprecated.Configure this Safelist to preserve relative links in an element's URL attribute, or convert them to absolute links.static Whitelist
relaxed()
Deprecated.Whitelist
removeAttributes(String tag, String... attributes)
Deprecated.Remove a list of allowed attributes from a tag.Whitelist
removeEnforcedAttribute(String tag, String attribute)
Deprecated.Remove a previously configured enforced attribute from a tag.Whitelist
removeProtocols(String tag, String attribute, String... removeProtocols)
Deprecated.Remove allowed URL protocols for an element's URL attribute.Whitelist
removeTags(String... tags)
Deprecated.Remove a list of allowed elements from a safelist.static Whitelist
simpleText()
Deprecated.
-
Constructor Details
-
Method Details
-
basic
Deprecated. -
basicWithImages
Deprecated. -
none
Deprecated. -
relaxed
Deprecated. -
simpleText
Deprecated. -
addTags
Deprecated.Description copied from class:Safelist
Add 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:Safelist
Remove a list of allowed elements from a safelist. (If a tag is not allowed, it will be removed from the HTML.)- Overrides:
removeTags
in classSafelist
- Parameters:
tags
- tag names to disallow- Returns:
- this (for chaining)
-
addAttributes
Deprecated.Description copied from class:Safelist
Add 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")
allowshref
andclass
attributes ona
tags.To make an attribute valid for all tags, use the pseudo tag
:all
, e.g.addAttributes(":all", "class")
.- Overrides:
addAttributes
in 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:Safelist
Remove 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")
disallowshref
andclass
attributes ona
tags.To make an attribute invalid for all tags, use the pseudo tag
:all
, e.g.removeAttributes(":all", "class")
.- Overrides:
removeAttributes
in 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:Safelist
Add 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 alla
tags output as<a href="..." rel="nofollow">
- Overrides:
addEnforcedAttribute
in 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:Safelist
Remove a previously configured enforced attribute from a tag.- Overrides:
removeEnforcedAttribute
in classSafelist
- Parameters:
tag
- The tag the enforced attribute is for.attribute
- The attribute name- Returns:
- this (for chaining)
-
preserveRelativeLinks
Deprecated.Description copied from class:Safelist
Configure 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 URI
set when parsing, so that the link's protocol can be confirmed. Regardless of the setting of thepreserve relative links
option, the link must be resolvable against the base URI to an allowed protocol; otherwise the attribute will be removed.- Overrides:
preserveRelativeLinks
in classSafelist
- Parameters:
preserve
-true
to 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:Safelist
Add 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:
addProtocols
in 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:Safelist
Remove 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:
removeProtocols
in 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:Safelist
Test if the supplied tag is allowed by this safelist -
isSafeAttribute
Deprecated.Description copied from class:Safelist
Test if the supplied attribute is allowed by this safelist for this tag- Overrides:
isSafeAttribute
in classSafelist
- Parameters:
tagName
- tag to consider allowing the attribute inel
- element under test, to confirm protocolattr
- attribute under test- Returns:
- true if allowed
-