2929package org .owasp .html ;
3030
3131import java .util .ArrayList ;
32+ import java .util .Collections ;
3233import java .util .HashMap ;
3334import java .util .HashSet ;
3435import java .util .LinkedHashMap ;
@@ -170,7 +171,7 @@ public class HtmlPolicyBuilder {
170171 for (String elementName : DEFAULT_SKIP_IF_EMPTY ) {
171172 builder .put (elementName , HtmlTagSkipType .SKIP_BY_DEFAULT );
172173 }
173- DEFAULT_SKIP_TAG_MAP_IF_EMPTY_ATTR = Map . copyOf (builder );
174+ DEFAULT_SKIP_TAG_MAP_IF_EMPTY_ATTR = Collections . unmodifiableMap (builder );
174175 }
175176
176177 /**
@@ -347,7 +348,7 @@ public AttributeBuilder allowAttributes(String... attributeNames) {
347348 for (String attributeName : attributeNames ) {
348349 builder .add (HtmlLexer .canonicalAttributeName (attributeName ));
349350 }
350- return new AttributeBuilder (List . copyOf (builder ));
351+ return new AttributeBuilder (Collections . unmodifiableList (builder ));
351352 }
352353
353354 /**
@@ -647,7 +648,7 @@ AttributePolicy makeGuard(AttributeGuardIntermediates intermediates) {
647648 }
648649
649650 });
650- ATTRIBUTE_GUARDS = Map . copyOf (builder );
651+ ATTRIBUTE_GUARDS = Collections . unmodifiableMap (builder );
651652 }
652653
653654 /**
@@ -686,17 +687,17 @@ public <CTX> HtmlSanitizer.Policy build(
686687 * each backed by a different output channel.
687688 */
688689 public PolicyFactory toFactory () {
689- Set <String > textContainerSet = new HashSet <>();
690+ Set <String > textContainerSetBuilder = new HashSet <>();
690691 for (Map .Entry <String , Boolean > textContainer
691692 : this .textContainers .entrySet ()) {
692693 if (Boolean .TRUE .equals (textContainer .getValue ())) {
693- textContainerSet .add (textContainer .getKey ());
694+ textContainerSetBuilder .add (textContainer .getKey ());
694695 }
695696 }
696697 CompiledState compiled = compilePolicies ();
697698
698699 return new PolicyFactory (
699- compiled .compiledPolicies , Set . copyOf ( textContainerSet ),
700+ compiled .compiledPolicies , Collections . unmodifiableSet ( textContainerSetBuilder ),
700701 Map .copyOf (compiled .globalAttrPolicies ),
701702 preprocessor , postprocessor );
702703 }
@@ -812,7 +813,7 @@ private CompiledState compilePolicies() {
812813 elAttrPolicies = Map .of ();
813814 }
814815
815- Map <String , AttributePolicy > attrs
816+ Map <String , AttributePolicy > attrsBuilder
816817 = new HashMap <>();
817818
818819 for (Map .Entry <String , AttributePolicy > ape : elAttrPolicies .entrySet ()) {
@@ -822,7 +823,7 @@ private CompiledState compilePolicies() {
822823 if (globalAttrPolicies .containsKey (attributeName )) { continue ; }
823824 AttributePolicy policy = ape .getValue ();
824825 if (!AttributePolicy .REJECT_ALL_ATTRIBUTE_POLICY .equals (policy )) {
825- attrs .put (attributeName , policy );
826+ attrsBuilder .put (attributeName , policy );
826827 }
827828 }
828829 for (Map .Entry <String , AttributePolicy > ape
@@ -831,21 +832,21 @@ private CompiledState compilePolicies() {
831832 AttributePolicy policy = AttributePolicy .Util .join (
832833 elAttrPolicies .get (attributeName ), ape .getValue ());
833834 if (!AttributePolicy .REJECT_ALL_ATTRIBUTE_POLICY .equals (policy )) {
834- attrs .put (attributeName , policy );
835+ attrsBuilder .put (attributeName , policy );
835836 }
836837 }
837838
838839 policiesBuilder .put (
839840 elementName ,
840841 new ElementAndAttributePolicies (
841842 elementName ,
842- elPolicy , Map . copyOf ( attrs ),
843+ elPolicy , Collections . unmodifiableMap ( attrsBuilder ),
843844 getHtmlTagSkipType (elementName )
844845 )
845846 );
846847 }
847848 compiledState = new CompiledState (
848- globalAttrPolicies , Map . copyOf (policiesBuilder ));
849+ globalAttrPolicies , Collections . unmodifiableMap (policiesBuilder ));
849850 return compiledState ;
850851 }
851852
@@ -982,7 +983,7 @@ public HtmlPolicyBuilder onElements(String... elementNames) {
982983 builder .add (HtmlLexer .canonicalElementName (elementName ));
983984 }
984985 return HtmlPolicyBuilder .this .allowAttributesOnElements (
985- policy , attributeNames , List . copyOf (builder ));
986+ policy , attributeNames , Collections . unmodifiableList (builder ));
986987 }
987988 }
988989
0 commit comments