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
@Deprecated public class Whitelist extends Safelist
Constructor and Description |
---|
Whitelist()
Deprecated.
|
Whitelist(Safelist copy)
Deprecated.
|
Modifier and Type | Method and 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 tag
|
protected boolean |
isSafeTag(String tag)
Deprecated.
Test if the supplied tag is allowed by this safelist
|
static 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.
|
public Whitelist()
public Whitelist(Safelist copy)
public static Whitelist basic()
public static Whitelist basicWithImages()
public static Whitelist none()
public static Whitelist relaxed()
public static Whitelist simpleText()
public Whitelist addTags(String... tags)
Safelist
public Whitelist removeTags(String... tags)
Safelist
removeTags
in class Safelist
tags
- tag names to disallowpublic Whitelist addAttributes(String tag, String... attributes)
Safelist
E.g.: addAttributes("a", "href", "class")
allows href
and class
attributes
on a
tags.
To make an attribute valid for all tags, use the pseudo tag :all
, e.g.
addAttributes(":all", "class")
.
addAttributes
in class Safelist
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 tagpublic Whitelist removeAttributes(String tag, String... attributes)
Safelist
E.g.: removeAttributes("a", "href", "class")
disallows href
and class
attributes on a
tags.
To make an attribute invalid for all tags, use the pseudo tag :all
, e.g.
removeAttributes(":all", "class")
.
removeAttributes
in class Safelist
tag
- The tag the attributes are for.attributes
- List of invalid attributes for the tagpublic Whitelist addEnforcedAttribute(String tag, String attribute, String value)
Safelist
E.g.: addEnforcedAttribute("a", "rel", "nofollow")
will make all a
tags output as
<a href="..." rel="nofollow">
addEnforcedAttribute
in class Safelist
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 valuepublic Whitelist removeEnforcedAttribute(String tag, String attribute)
Safelist
removeEnforcedAttribute
in class Safelist
tag
- The tag the enforced attribute is for.attribute
- The attribute namepublic Whitelist preserveRelativeLinks(boolean preserve)
Safelist
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 the preserve relative
links
option, the link must be resolvable against the base URI to an allowed protocol; otherwise the attribute
will be removed.
preserveRelativeLinks
in class Safelist
preserve
- true
to allow relative links, false
(default) to denySafelist.addProtocols(java.lang.String, java.lang.String, java.lang.String...)
public Whitelist addProtocols(String tag, String attribute, String... protocols)
Safelist
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", "#")
addProtocols
in class Safelist
tag
- Tag the URL protocol is forattribute
- Attribute nameprotocols
- List of valid protocolspublic Whitelist removeProtocols(String tag, String attribute, String... removeProtocols)
Safelist
E.g.: removeProtocols("a", "href", "ftp")
removeProtocols
in class Safelist
tag
- Tag the URL protocol is forattribute
- Attribute nameremoveProtocols
- List of invalid protocolsprotected boolean isSafeTag(String tag)
Safelist
protected boolean isSafeAttribute(String tagName, Element el, Attribute attr)
Safelist
isSafeAttribute
in class Safelist
tagName
- tag to consider allowing the attribute inel
- element under test, to confirm protocolattr
- attribute under testCopyright © 2009–2024 Jonathan Hedley. All rights reserved.