diff --git a/parent/pom.xml b/parent/pom.xml
index ec4f2631..ceaac711 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -88,9 +88,12 @@ application while protecting against XSS.
UTF-8
UTF-8
- 30.1-jre
+ 9
+ 9
+ 9
+
@@ -184,8 +187,8 @@ application while protecting against XSS.
maven-compiler-plugin
3.3
- 6
- 6
+ 9
+ 9
@@ -234,15 +237,10 @@ application while protecting against XSS.
-
- com.google.guava
- guava
- ${guava.version}
-
commons-codec
commons-codec
- [1.4,)
+ [1.15,)
com.google.code.findbugs
diff --git a/pom.xml b/pom.xml
index ed9b523f..78532102 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,6 +60,11 @@
org.apache.felix
maven-bundle-plugin
+
+
+ org.owasp.html
+
+
org.apache.maven.plugins
@@ -81,10 +86,6 @@
-
- com.google.guava
- guava
-
commons-codec
commons-codec
diff --git a/src/main/java/org/owasp/html/AttributePolicy.java b/src/main/java/org/owasp/html/AttributePolicy.java
index 7f279db5..56668f87 100644
--- a/src/main/java/org/owasp/html/AttributePolicy.java
+++ b/src/main/java/org/owasp/html/AttributePolicy.java
@@ -28,9 +28,8 @@
package org.owasp.html;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-
+import java.util.List;
+import java.util.Optional;
import java.util.Set;
import javax.annotation.CheckReturnValue;
@@ -91,11 +90,11 @@ static final class AttributePolicyJoiner
}
@Override
- Optional> split(AttributePolicy x) {
+ Optional> split(AttributePolicy x) {
if (x instanceof JoinedAttributePolicy) {
return Optional.of(((JoinedAttributePolicy) x).policies);
} else {
- return Optional.absent();
+ return Optional.empty();
}
}
diff --git a/src/main/java/org/owasp/html/CssSchema.java b/src/main/java/org/owasp/html/CssSchema.java
index d344f23d..b9c6ae64 100644
--- a/src/main/java/org/owasp/html/CssSchema.java
+++ b/src/main/java/org/owasp/html/CssSchema.java
@@ -28,18 +28,18 @@
package org.owasp.html;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
+import java.util.TreeSet;
import javax.annotation.Nullable;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
/** Describes the kinds of tokens a CSS property's value can safely contain. */
@TCB
public final class CssSchema {
@@ -54,11 +54,11 @@ public static final class Property {
/** A bitfield of BIT_* constants describing groups of allowed tokens. */
final int bits;
/** Specific allowed values. */
- final ImmutableSet literals;
+ final Set literals;
/**
* Maps lower-case function tokens to the schema key for their parameters.
*/
- final ImmutableMap fnKeys;
+ final Map fnKeys;
/**
* @param bits A bitfield of BIT_* constants describing groups of allowed tokens.
@@ -66,11 +66,11 @@ public static final class Property {
* @param fnKeys Maps lower-case function tokens to the schema key for their parameters.
*/
public Property(
- int bits, ImmutableSet literals,
- ImmutableMap fnKeys) {
+ int bits, Set literals,
+ Map fnKeys) {
this.bits = bits;
- this.literals = literals;
- this.fnKeys = fnKeys;
+ this.literals = Set.copyOf(literals);
+ this.fnKeys = Map.copyOf(fnKeys);
}
@Override
@@ -125,11 +125,11 @@ public boolean equals(Object obj) {
static final int BIT_UNICODE_RANGE = 128;
static final Property DISALLOWED = new Property(
- 0, ImmutableSet.of(), ImmutableMap.of());
+ 0, Collections.emptySet(), Collections.emptyMap());
- private final ImmutableMap properties;
+ private final Map properties;
- private CssSchema(ImmutableMap properties) {
+ private CssSchema(Map properties) {
if (properties == null) { throw new NullPointerException(); }
this.properties = properties;
}
@@ -144,14 +144,14 @@ private CssSchema(ImmutableMap properties) {
*/
public static CssSchema withProperties(
Iterable extends String> propertyNames) {
- ImmutableMap.Builder propertiesBuilder =
- ImmutableMap.builder();
+ Map propertiesBuilder =
+ new HashMap<>();
for (String propertyName : propertyNames) {
Property prop = DEFINITIONS.get(propertyName);
if (prop == null) { throw new IllegalArgumentException(propertyName); }
propertiesBuilder.put(propertyName, prop);
}
- return new CssSchema(propertiesBuilder.build());
+ return new CssSchema(Map.copyOf(propertiesBuilder));
}
/**
@@ -161,8 +161,8 @@ public static CssSchema withProperties(
*/
public static CssSchema withProperties(
Map extends String, ? extends Property> properties) {
- ImmutableMap propertyMap =
- ImmutableMap.copyOf(properties);
+ Map propertyMap =
+ new HashMap<>();
// check that all fnKeys are defined in properties.
for (Map.Entry e : propertyMap.entrySet()) {
Property property = e.getValue();
@@ -174,7 +174,7 @@ public static CssSchema withProperties(
}
}
}
- return new CssSchema(propertyMap);
+ return new CssSchema(Map.copyOf(propertyMap));
}
/**
@@ -187,13 +187,17 @@ public static CssSchema withProperties(
*/
public static CssSchema union(CssSchema... cssSchemas) {
if (cssSchemas.length == 1) { return cssSchemas[0]; }
- Map properties = Maps.newLinkedHashMap();
+ Map properties = new LinkedHashMap<>();
for (CssSchema cssSchema : cssSchemas) {
for (Map.Entry e : cssSchema.properties.entrySet()) {
String name = e.getKey();
Property newProp = e.getValue();
- Preconditions.checkNotNull(name);
- Preconditions.checkNotNull(newProp);
+ if (Objects.isNull(name)) {
+ throw new NullPointerException("An entry was returned with null key from cssSchema.properties");
+ }
+ if (Objects.isNull(newProp)) {
+ throw new NullPointerException("An entry was returned with null value from cssSchema.properties");
+ }
Property oldProp = properties.put(name, newProp);
if (oldProp != null && !oldProp.equals(newProp)) {
throw new IllegalArgumentException(
@@ -201,7 +205,7 @@ public static CssSchema union(CssSchema... cssSchemas) {
}
}
}
- return new CssSchema(ImmutableMap.copyOf(properties));
+ return new CssSchema(Map.copyOf(properties));
}
/**
@@ -221,6 +225,7 @@ Property forKey(String propertyName) {
int n = propertyNameCanon.length();
if (n != 0 && propertyNameCanon.charAt(0) == '-') {
String barePropertyNameCanon = stripVendorPrefix(propertyNameCanon);
+ if (barePropertyNameCanon == null) { return DISALLOWED; }
property = properties.get(barePropertyNameCanon);
if (property != null) { return property; }
}
@@ -252,14 +257,13 @@ Property forKey(String propertyName) {
}
/** Maps lower-cased CSS property names to information about them. */
- static final ImmutableMap DEFINITIONS;
+ static final Map DEFINITIONS;
static {
- ImmutableMap zeroFns = ImmutableMap.of();
- ImmutableMap.Builder builder
- = ImmutableMap.builder();
- ImmutableSet mozBorderRadiusLiterals0 = ImmutableSet.of("/");
- ImmutableSet mozOpacityLiterals0 = ImmutableSet.of("inherit");
- ImmutableSet mozOutlineLiterals0 = ImmutableSet.of(
+ Map zeroFns = Collections.emptyMap();
+ Map builder = new HashMap<>();
+ Set mozBorderRadiusLiterals0 = Set.of("/");
+ Set mozOpacityLiterals0 = Set.of("inherit");
+ Set mozOutlineLiterals0 = Set.of(
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral",
@@ -287,122 +291,121 @@ Property forKey(String propertyName) {
"silver", "skyblue", "slateblue", "slategray", "snow", "springgreen",
"steelblue", "tan", "teal", "thistle", "tomato", "turquoise", "violet",
"wheat", "white", "whitesmoke", "yellow", "yellowgreen");
- ImmutableSet mozOutlineLiterals1 = ImmutableSet.of(
+ Set mozOutlineLiterals1 = Set.of(
"dashed", "dotted", "double", "groove", "outset", "ridge", "solid");
- ImmutableSet mozOutlineLiterals2 = ImmutableSet.of("thick", "thin");
- ImmutableSet mozOutlineLiterals3 = ImmutableSet.of(
+ Set mozOutlineLiterals2 = Set.of("thick", "thin");
+ Set mozOutlineLiterals3 = Set.of(
"hidden", "inherit", "inset", "invert", "medium", "none");
- ImmutableMap mozOutlineFunctions =
- ImmutableMap.of(
+ Map mozOutlineFunctions =
+ Map.of(
"rgb(", "rgb()", "rgba(", "rgba()",
"hsl(", "hsl()", "hsla(", "hsla()");
- ImmutableSet mozOutlineColorLiterals0 =
- ImmutableSet.of("inherit", "invert");
- ImmutableSet mozOutlineStyleLiterals0 =
- ImmutableSet.of("hidden", "inherit", "inset", "none");
- ImmutableSet mozOutlineWidthLiterals0 =
- ImmutableSet.of("inherit", "medium");
- ImmutableSet oTextOverflowLiterals0 =
- ImmutableSet.of("clip", "ellipsis");
- ImmutableSet azimuthLiterals0 = ImmutableSet.of(
+ Set mozOutlineColorLiterals0 =
+ Set.of("inherit", "invert");
+ Set mozOutlineStyleLiterals0 =
+ Set.of("hidden", "inherit", "inset", "none");
+ Set mozOutlineWidthLiterals0 =
+ Set.of("inherit", "medium");
+ Set oTextOverflowLiterals0 =
+ Set.of("clip", "ellipsis");
+ Set azimuthLiterals0 = Set.of(
"behind", "center-left", "center-right", "far-left", "far-right",
"left-side", "leftwards", "right-side", "rightwards");
- ImmutableSet azimuthLiterals1 = ImmutableSet.of("left", "right");
- ImmutableSet azimuthLiterals2 =
- ImmutableSet.of("center", "inherit");
- ImmutableSet backgroundLiterals0 = ImmutableSet.of(
+ Set azimuthLiterals1 = Set.of("left", "right");
+ Set azimuthLiterals2 =
+ Set.of("center", "inherit");
+ Set backgroundLiterals0 = Set.of(
"border-box", "contain", "content-box", "cover", "padding-box");
- ImmutableSet backgroundLiterals1 =
- ImmutableSet.of("no-repeat", "repeat-x", "repeat-y", "round", "space");
- ImmutableSet backgroundLiterals2 = ImmutableSet.of("bottom", "top");
- ImmutableSet backgroundLiterals3 = ImmutableSet.of(
+ Set backgroundLiterals1 =
+ Set.of("no-repeat", "repeat-x", "repeat-y", "round", "space");
+ Set backgroundLiterals2 = Set.of("bottom", "top");
+ Set backgroundLiterals3 = Set.of(
",", "/", "auto", "center", "fixed", "inherit", "local", "none",
"repeat", "scroll", "transparent");
- ImmutableMap backgroundFunctions =
- ImmutableMap.builder()
- .put("image(", "image()")
- .put("linear-gradient(", "linear-gradient()")
- .put("radial-gradient(", "radial-gradient()")
- .put("repeating-linear-gradient(", "repeating-linear-gradient()")
- .put("repeating-radial-gradient(", "repeating-radial-gradient()")
- .put("rgb(", "rgb()").put("rgba(", "rgba()")
- .put("hsl(", "hsl()").put("hsla(", "hsla()")
- .build();
- ImmutableSet backgroundAttachmentLiterals0 =
- ImmutableSet.of(",", "fixed", "local", "scroll");
- ImmutableSet backgroundColorLiterals0 =
- ImmutableSet.of("inherit", "transparent");
- ImmutableSet backgroundImageLiterals0 =
- ImmutableSet.of(",", "none");
- ImmutableMap backgroundImageFunctions =
- ImmutableMap.of(
+ Map backgroundFunctions =
+ Map.of(
+ "image(", "image()",
+ "linear-gradient(", "linear-gradient()",
+ "radial-gradient(", "radial-gradient()",
+ "repeating-linear-gradient(", "repeating-linear-gradient()",
+ "repeating-radial-gradient(", "repeating-radial-gradient()",
+ "rgb(", "rgb()", "rgba(", "rgba()",
+ "hsl(", "hsl()", "hsla(", "hsla()");
+ Set backgroundAttachmentLiterals0 =
+ Set.of(",", "fixed", "local", "scroll");
+ Set backgroundColorLiterals0 =
+ Set.of("inherit", "transparent");
+ Set backgroundImageLiterals0 =
+ Set.of(",", "none");
+ Map backgroundImageFunctions =
+ Map.of(
"image(", "image()",
"linear-gradient(", "linear-gradient()",
"radial-gradient(", "radial-gradient()",
"repeating-linear-gradient(", "repeating-linear-gradient()",
"repeating-radial-gradient(", "repeating-radial-gradient()");
- ImmutableSet backgroundPositionLiterals0 = ImmutableSet.of(
+ Set backgroundPositionLiterals0 = Set.of(
",", "center");
- ImmutableSet backgroundRepeatLiterals0 = ImmutableSet.of(
+ Set backgroundRepeatLiterals0 = Set.of(
",", "repeat");
- ImmutableSet borderLiterals0 = ImmutableSet.of(
+ Set borderLiterals0 = Set.of(
"hidden", "inherit", "inset", "medium", "none", "transparent");
- ImmutableSet borderCollapseLiterals0 = ImmutableSet.of(
+ Set borderCollapseLiterals0 = Set.of(
"collapse", "inherit", "separate");
- ImmutableSet bottomLiterals0 = ImmutableSet.of("auto", "inherit");
- ImmutableSet boxShadowLiterals0 = ImmutableSet.of(
+ Set bottomLiterals0 = Set.of("auto", "inherit");
+ Set boxShadowLiterals0 = Set.of(
",", "inset", "none");
- ImmutableSet clearLiterals0 = ImmutableSet.of(
+ Set clearLiterals0 = Set.of(
"both", "inherit", "none");
- ImmutableMap clipFunctions =
- ImmutableMap.of("rect(", "rect()");
- ImmutableSet contentLiterals0 = ImmutableSet.of("none", "normal");
- ImmutableSet cueLiterals0 = ImmutableSet.of("inherit", "none");
- ImmutableSet cursorLiterals0 = ImmutableSet.of(
+ Map clipFunctions =
+ Map.of("rect(", "rect()");
+ Set contentLiterals0 = Set.of("none", "normal");
+ Set cueLiterals0 = Set.of("inherit", "none");
+ Set cursorLiterals0 = Set.of(
"all-scroll", "col-resize", "crosshair", "default", "e-resize",
"hand", "help", "move", "n-resize", "ne-resize", "no-drop",
"not-allowed", "nw-resize", "pointer", "progress", "row-resize",
"s-resize", "se-resize", "sw-resize", "text", "vertical-text",
"w-resize", "wait");
- ImmutableSet cursorLiterals1 = ImmutableSet.of(
+ Set cursorLiterals1 = Set.of(
",", "auto", "inherit");
- ImmutableSet directionLiterals0 = ImmutableSet.of("ltr", "rtl");
- ImmutableSet displayLiterals0 = ImmutableSet.of(
+ Set directionLiterals0 = Set.of("ltr", "rtl");
+ Set displayLiterals0 = Set.of(
"-moz-inline-box", "-moz-inline-stack", "block", "inline",
"inline-block", "inline-table", "list-item", "run-in", "table",
"table-caption", "table-cell", "table-column", "table-column-group",
"table-footer-group", "table-header-group", "table-row",
"table-row-group");
- ImmutableSet elevationLiterals0 = ImmutableSet.of(
+ Set elevationLiterals0 = Set.of(
"above", "below", "higher", "level", "lower");
- ImmutableSet emptyCellsLiterals0 = ImmutableSet.of("hide", "show");
- //ImmutableMap filterFunctions =
- // ImmutableMap.of("alpha(", "alpha()");
- ImmutableSet fontLiterals0 = ImmutableSet.of(
+ Set emptyCellsLiterals0 = Set.of("hide", "show");
+ //Map filterFunctions =
+ // Map.of("alpha(", "alpha()");
+ Set fontLiterals0 = Set.of(
"100", "200", "300", "400", "500", "600", "700", "800", "900", "bold",
"bolder", "lighter");
- ImmutableSet fontLiterals1 = ImmutableSet.of(
+ Set fontLiterals1 = Set.of(
"large", "larger", "small", "smaller", "x-large", "x-small",
"xx-large", "xx-small", "xxx-large", "medium");
- ImmutableSet fontLiterals2 = ImmutableSet.of(
+ Set fontLiterals2 = Set.of(
"caption", "icon", "menu", "message-box", "small-caption",
"status-bar");
- ImmutableSet fontLiterals3 = ImmutableSet.of(
+ Set fontLiterals3 = Set.of(
"cursive", "fantasy", "monospace", "sans-serif", "serif");
- ImmutableSet fontLiterals4 = ImmutableSet.of("italic", "oblique");
- ImmutableSet fontLiterals5 = ImmutableSet.of(
+ Set fontLiterals4 = Set.of("italic", "oblique");
+ Set fontLiterals5 = Set.of(
",", "/", "inherit", "medium", "normal", "small-caps");
- ImmutableSet fontFamilyLiterals0 = ImmutableSet.of(",", "inherit");
- ImmutableSet fontStretchLiterals0 = ImmutableSet.of(
+ Set fontFamilyLiterals0 = Set.of(",", "inherit");
+ Set fontStretchLiterals0 = Set.of(
"condensed", "expanded", "extra-condensed", "extra-expanded",
"narrower", "semi-condensed", "semi-expanded", "ultra-condensed",
"ultra-expanded", "wider");
- ImmutableSet fontStretchLiterals1 = ImmutableSet.of("normal");
- ImmutableSet fontStyleLiterals0 = ImmutableSet.of(
+ Set fontStretchLiterals1 = Set.of("normal");
+ Set fontStyleLiterals0 = Set.of(
"inherit", "normal");
- ImmutableSet fontVariantLiterals0 = ImmutableSet.of(
+ Set fontVariantLiterals0 = Set.of(
"inherit", "normal", "small-caps");
- ImmutableSet listStyleLiterals0 = ImmutableSet.of(
+ Set listStyleLiterals0 = Set.of(
"armenian", "cjk-decimal", "decimal", "decimal-leading-zero", "disc",
"disclosure-closed", "disclosure-open", "ethiopic-numeric", "georgian",
"hebrew", "hiragana", "hiragana-iroha", "japanese-formal",
@@ -412,78 +415,78 @@ Property forKey(String propertyName) {
"lower-roman", "simp-chinese-formal", "simp-chinese-informal",
"square", "trad-chinese-formal", "trad-chinese-informal",
"upper-alpha", "upper-latin", "upper-roman");
- ImmutableSet listStyleLiterals1 = ImmutableSet.of(
+ Set listStyleLiterals1 = Set.of(
"inside", "outside");
- ImmutableSet listStyleLiterals2 = ImmutableSet.of(
+ Set listStyleLiterals2 = Set.of(
"circle", "inherit", "none");
- ImmutableSet maxHeightLiterals0 = ImmutableSet.of(
+ Set maxHeightLiterals0 = Set.of(
"auto", "inherit", "none");
- ImmutableSet overflowLiterals0 = ImmutableSet.of(
+ Set overflowLiterals0 = Set.of(
"auto", "hidden", "inherit", "scroll", "visible");
- ImmutableSet overflowXLiterals0 = ImmutableSet.of(
+ Set overflowXLiterals0 = Set.of(
"no-content", "no-display");
- ImmutableSet overflowXLiterals1 = ImmutableSet.of(
+ Set overflowXLiterals1 = Set.of(
"auto", "hidden", "scroll", "visible");
- ImmutableSet pageBreakAfterLiterals0 = ImmutableSet.of(
+ Set pageBreakAfterLiterals0 = Set.of(
"always", "auto", "avoid", "inherit");
- ImmutableSet pageBreakInsideLiterals0 = ImmutableSet.of(
+ Set pageBreakInsideLiterals0 = Set.of(
"auto", "avoid", "inherit");
- ImmutableSet pitchLiterals0 = ImmutableSet.of(
+ Set pitchLiterals0 = Set.of(
"high", "low", "x-high", "x-low");
- ImmutableSet playDuringLiterals0 = ImmutableSet.of(
+ Set playDuringLiterals0 = Set.of(
"auto", "inherit", "mix", "none", "repeat");
- ImmutableSet positionLiterals0 = ImmutableSet.of(
+ Set positionLiterals0 = Set.of(
"absolute", "relative", "static");
- ImmutableSet speakLiterals0 = ImmutableSet.of(
+ Set speakLiterals0 = Set.of(
"inherit", "none", "normal", "spell-out");
- ImmutableSet speakHeaderLiterals0 = ImmutableSet.of(
+ Set speakHeaderLiterals0 = Set.of(
"always", "inherit", "once");
- ImmutableSet speakNumeralLiterals0 = ImmutableSet.of(
+ Set speakNumeralLiterals0 = Set.of(
"continuous", "digits");
- ImmutableSet speakPunctuationLiterals0 = ImmutableSet.of(
+ Set speakPunctuationLiterals0 = Set.of(
"code", "inherit", "none");
- ImmutableSet speechRateLiterals0 = ImmutableSet.of(
+ Set speechRateLiterals0 = Set.of(
"fast", "faster", "slow", "slower", "x-fast", "x-slow");
- ImmutableSet tableLayoutLiterals0 = ImmutableSet.of(
+ Set tableLayoutLiterals0 = Set.of(
"auto", "fixed", "inherit");
- ImmutableSet textAlignLiterals0 = ImmutableSet.of(
+ Set textAlignLiterals0 = Set.of(
"center", "inherit", "justify");
- ImmutableSet textDecorationLiterals0 = ImmutableSet.of(
+ Set textDecorationLiterals0 = Set.of(
"blink", "line-through", "overline", "underline");
- ImmutableSet textTransformLiterals0 = ImmutableSet.of(
+ Set textTransformLiterals0 = Set.of(
"capitalize", "lowercase", "uppercase");
- ImmutableSet textWrapLiterals0 = ImmutableSet.of(
+ Set textWrapLiterals0 = Set.of(
"suppress", "unrestricted");
- ImmutableSet unicodeBidiLiterals0 = ImmutableSet.of(
+ Set unicodeBidiLiterals0 = Set.of(
"bidi-override", "embed");
- ImmutableSet verticalAlignLiterals0 = ImmutableSet.of(
+ Set verticalAlignLiterals0 = Set.of(
"baseline", "middle", "sub", "super", "text-bottom", "text-top");
- ImmutableSet visibilityLiterals0 = ImmutableSet.of(
+ Set visibilityLiterals0 = Set.of(
"collapse", "hidden", "inherit", "visible");
- ImmutableSet voiceFamilyLiterals0 = ImmutableSet.of(
+ Set voiceFamilyLiterals0 = Set.of(
"child", "female", "male");
- ImmutableSet volumeLiterals0 = ImmutableSet.of(
+ Set volumeLiterals0 = Set.of(
"loud", "silent", "soft", "x-loud", "x-soft");
- ImmutableSet whiteSpaceLiterals0 = ImmutableSet.of(
+ Set whiteSpaceLiterals0 = Set.of(
"-moz-pre-wrap", "-o-pre-wrap", "-pre-wrap", "nowrap", "pre",
"pre-line", "pre-wrap");
- ImmutableSet wordWrapLiterals0 = ImmutableSet.of(
+ Set wordWrapLiterals0 = Set.of(
"break-word", "normal");
- ImmutableSet rgb$FunLiterals0 = ImmutableSet.of(",");
- ImmutableSet linearGradient$FunLiterals0 = ImmutableSet.of(
+ Set rgb$FunLiterals0 = Set.of(",");
+ Set linearGradient$FunLiterals0 = Set.of(
",", "to");
- ImmutableSet radialGradient$FunLiterals0 = ImmutableSet.of(
+ Set radialGradient$FunLiterals0 = Set.of(
"at", "closest-corner", "closest-side", "ellipse", "farthest-corner",
"farthest-side");
- ImmutableSet radialGradient$FunLiterals1 = ImmutableSet.of(
+ Set radialGradient$FunLiterals1 = Set.of(
",", "center", "circle");
- ImmutableSet rect$FunLiterals0 = ImmutableSet.of(",", "auto");
- //ImmutableSet alpha$FunLiterals0 = ImmutableSet.of("=", "opacity");
+ Set rect$FunLiterals0 = Set.of(",", "auto");
+ //Set alpha$FunLiterals0 = Set.of("=", "opacity");
Property mozBorderRadius =
new Property(5, mozBorderRadiusLiterals0, zeroFns);
builder.put("-moz-border-radius", mozBorderRadius);
Property mozBorderRadiusBottomleft =
- new Property(5, ImmutableSet.of(), zeroFns);
+ new Property(5, Set.of(), zeroFns);
builder.put("-moz-border-radius-bottomleft", mozBorderRadiusBottomleft);
Property mozOpacity = new Property(1, mozOpacityLiterals0, zeroFns);
builder.put("-moz-opacity", mozOpacity);
@@ -843,19 +846,18 @@ Property forKey(String propertyName) {
builder.put("z-index", bottom);
builder.put("repeating-linear-gradient()", linearGradient$Fun);
builder.put("repeating-radial-gradient()", radialGradient$Fun);
- DEFINITIONS = builder.build();
+ DEFINITIONS = Map.copyOf(builder);
}
- private static ImmutableSet union(
- @SuppressWarnings("unchecked") ImmutableSet... subsets) {
- ImmutableSet.Builder all = ImmutableSet.builder();
- for (ImmutableSet subset : subsets) {
+ private static Set union(Set... subsets) {
+ Set all = new HashSet<>();
+ for (Set subset : subsets) {
all.addAll(subset);
}
- return all.build();
+ return Set.copyOf(all);
}
- static final ImmutableSet DEFAULT_WHITELIST = ImmutableSet.of(
+ static final Set DEFAULT_WHITELIST = Set.of(
"-moz-border-radius",
"-moz-border-radius-bottomleft",
"-moz-border-radius-bottomright",
@@ -1002,10 +1004,10 @@ private static ImmutableSet union(
/** Dumps key and literal list to stdout for easy examination. */
public static void main(String... argv) {
- SortedSet keys = Sets.newTreeSet();
- SortedSet literals = Sets.newTreeSet();
+ SortedSet keys = new TreeSet<>();
+ SortedSet literals = new TreeSet<>();
- for (ImmutableMap.Entry e : DEFINITIONS.entrySet()) {
+ for (Map.Entry e : DEFINITIONS.entrySet()) {
keys.add(e.getKey());
literals.addAll(e.getValue().literals);
}
diff --git a/src/main/java/org/owasp/html/CssTokens.java b/src/main/java/org/owasp/html/CssTokens.java
index 7fd44904..626ecb29 100644
--- a/src/main/java/org/owasp/html/CssTokens.java
+++ b/src/main/java/org/owasp/html/CssTokens.java
@@ -31,12 +31,11 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.NoSuchElementException;
import javax.annotation.Nullable;
-import com.google.common.collect.ImmutableMap;
-
/**
* Given a string of CSS, produces a string of normalized CSS with certain
* useful properties detailed below.
@@ -1464,34 +1463,34 @@ private static int[] truncateOrShare(int[] arr, int limit) {
* See http://dev.w3.org/csswg/css-values/#lengths and
* http://dev.w3.org/csswg/css-values/#other-units
*/
- private static final Trie UNIT_TRIE = new Trie(
- ImmutableMap.builder()
- .put("em", LENGTH_UNIT_TYPE)
- .put("ex", LENGTH_UNIT_TYPE)
- .put("ch", LENGTH_UNIT_TYPE) // Width of zero character
- .put("rem", LENGTH_UNIT_TYPE) // Root element font-size
- .put("vh", LENGTH_UNIT_TYPE)
- .put("vw", LENGTH_UNIT_TYPE)
- .put("vmin", LENGTH_UNIT_TYPE)
- .put("vmax", LENGTH_UNIT_TYPE)
- .put("px", LENGTH_UNIT_TYPE)
- .put("mm", LENGTH_UNIT_TYPE)
- .put("cm", LENGTH_UNIT_TYPE)
- .put("in", LENGTH_UNIT_TYPE)
- .put("pt", LENGTH_UNIT_TYPE)
- .put("pc", LENGTH_UNIT_TYPE)
- .put("deg", ANGLE_UNIT_TYPE)
- .put("rad", ANGLE_UNIT_TYPE)
- .put("grad", ANGLE_UNIT_TYPE)
- .put("turn", ANGLE_UNIT_TYPE)
- .put("s", TIME_UNIT_TYPE)
- .put("ms", TIME_UNIT_TYPE)
- .put("hz", FREQUENCY_UNIT_TYPE)
- .put("khz", FREQUENCY_UNIT_TYPE)
- .put("dpi", RESOLUTION_UNIT_TYPE)
- .put("dpcm", RESOLUTION_UNIT_TYPE)
- .put("dppx", RESOLUTION_UNIT_TYPE)
- .build());
+ private static final Trie UNIT_TRIE = new Trie<>(
+ Map.ofEntries(
+ Map.entry("em", LENGTH_UNIT_TYPE),
+ Map.entry("ex", LENGTH_UNIT_TYPE),
+ Map.entry("ch", LENGTH_UNIT_TYPE), // Width of zero character
+ Map.entry("rem", LENGTH_UNIT_TYPE), // Root element font-size
+ Map.entry("vh", LENGTH_UNIT_TYPE),
+ Map.entry("vw", LENGTH_UNIT_TYPE),
+ Map.entry("vmin", LENGTH_UNIT_TYPE),
+ Map.entry("vmax", LENGTH_UNIT_TYPE),
+ Map.entry("px", LENGTH_UNIT_TYPE),
+ Map.entry("mm", LENGTH_UNIT_TYPE),
+ Map.entry("cm", LENGTH_UNIT_TYPE),
+ Map.entry("in", LENGTH_UNIT_TYPE),
+ Map.entry("pt", LENGTH_UNIT_TYPE),
+ Map.entry("pc", LENGTH_UNIT_TYPE),
+ Map.entry("deg", ANGLE_UNIT_TYPE),
+ Map.entry("rad", ANGLE_UNIT_TYPE),
+ Map.entry("grad", ANGLE_UNIT_TYPE),
+ Map.entry("turn", ANGLE_UNIT_TYPE),
+ Map.entry("s", TIME_UNIT_TYPE),
+ Map.entry("ms", TIME_UNIT_TYPE),
+ Map.entry("hz", FREQUENCY_UNIT_TYPE),
+ Map.entry("khz", FREQUENCY_UNIT_TYPE),
+ Map.entry("dpi", RESOLUTION_UNIT_TYPE),
+ Map.entry("dpcm", RESOLUTION_UNIT_TYPE),
+ Map.entry("dppx", RESOLUTION_UNIT_TYPE))
+ );
static boolean isWellKnownUnit(CharSequence s, int start, int end) {
if (start == end) { return false; }
diff --git a/src/main/java/org/owasp/html/ElementAndAttributePolicies.java b/src/main/java/org/owasp/html/ElementAndAttributePolicies.java
index 8f2cdca6..1097a572 100644
--- a/src/main/java/org/owasp/html/ElementAndAttributePolicies.java
+++ b/src/main/java/org/owasp/html/ElementAndAttributePolicies.java
@@ -28,9 +28,9 @@
package org.owasp.html;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
import javax.annotation.concurrent.Immutable;
/**
@@ -42,7 +42,7 @@
final class ElementAndAttributePolicies {
final String elementName;
final ElementPolicy elPolicy;
- final ImmutableMap attrPolicies;
+ final Map attrPolicies;
final HtmlTagSkipType htmlTagSkipType;
ElementAndAttributePolicies(
@@ -53,15 +53,15 @@ final class ElementAndAttributePolicies {
HtmlTagSkipType htmlTagSkipType) {
this.elementName = elementName;
this.elPolicy = elPolicy;
- this.attrPolicies = ImmutableMap.copyOf(attrPolicies);
+ this.attrPolicies = Map.copyOf(attrPolicies);
this.htmlTagSkipType = htmlTagSkipType;
}
ElementAndAttributePolicies and(ElementAndAttributePolicies p) {
assert elementName.equals(p.elementName):
elementName + " != " + p.elementName;
- ImmutableMap.Builder joinedAttrPolicies
- = ImmutableMap.builder();
+ Map joinedAttrPolicies
+ = new HashMap<>();
for (Map.Entry e : this.attrPolicies.entrySet()) {
String attrName = e.getKey();
AttributePolicy a = e.getValue();
@@ -81,7 +81,7 @@ ElementAndAttributePolicies and(ElementAndAttributePolicies p) {
return new ElementAndAttributePolicies(
elementName,
ElementPolicy.Util.join(elPolicy, p.elPolicy),
- joinedAttrPolicies.build(),
+ Map.copyOf(joinedAttrPolicies),
this.htmlTagSkipType.and(p.htmlTagSkipType));
}
@@ -98,7 +98,7 @@ ElementAndAttributePolicies andGlobals(
attrPolicy, globalAttrPolicy);
if (!joined.equals(attrPolicy)) {
if (anded == null) {
- anded = Maps.newLinkedHashMap();
+ anded = new LinkedHashMap<>();
anded.putAll(this.attrPolicies);
}
anded.put(attrName, joined);
@@ -109,7 +109,7 @@ ElementAndAttributePolicies andGlobals(
String attrName = e.getKey();
if (!this.attrPolicies.containsKey(attrName)) {
if (anded == null) {
- anded = Maps.newLinkedHashMap();
+ anded = new LinkedHashMap<>();
anded.putAll(this.attrPolicies);
}
anded.put(attrName, e.getValue());
diff --git a/src/main/java/org/owasp/html/ElementAndAttributePolicyBasedSanitizerPolicy.java b/src/main/java/org/owasp/html/ElementAndAttributePolicyBasedSanitizerPolicy.java
index c8da4617..4f78e2c8 100644
--- a/src/main/java/org/owasp/html/ElementAndAttributePolicyBasedSanitizerPolicy.java
+++ b/src/main/java/org/owasp/html/ElementAndAttributePolicyBasedSanitizerPolicy.java
@@ -28,16 +28,15 @@
package org.owasp.html;
+import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-
/**
* A sanitizer policy that applies element and attribute policies to tags.
*/
@@ -45,8 +44,8 @@
@NotThreadSafe
class ElementAndAttributePolicyBasedSanitizerPolicy
implements HtmlSanitizer.Policy {
- final ImmutableMap elAndAttrPolicies;
- final ImmutableSet allowedTextContainers;
+ final Map elAndAttrPolicies;
+ final Set allowedTextContainers;
private final HtmlStreamEventReceiver out;
/**
* True to skip textual content. Used to ignore the content of embedded CDATA
@@ -57,19 +56,19 @@ class ElementAndAttributePolicyBasedSanitizerPolicy
* Alternating input names and adjusted names of elements opened by the
* caller.
*/
- private final List openElementStack = Lists.newArrayList();
+ private final List openElementStack = new ArrayList<>();
ElementAndAttributePolicyBasedSanitizerPolicy(
HtmlStreamEventReceiver out,
- ImmutableMap elAndAttrPolicies,
- ImmutableSet allowedTextContainers) {
+ Map elAndAttrPolicies,
+ Set