Skip to content

Array out of bounds exception on HtmlPolicyBuilder initialization #247

Open
@mymhealthltd-joshengland

Description

Constructing a HtmlPolicyBuilder zero-defined global attributes, globally, leads to an Arry out of bounds exception

Here is sample code that produces the problem

new HtmlPolicyBuilder().allowElements().allowAttributes().globally().toFactory();

The exception comes form an un-guarded check on the zeroth element of the attributesNames list. In this situation, attribute names is empty and so has no zeroth element.

    public HtmlPolicyBuilder globally() {
      if(attributeNames.get(0).equals("style")) {
        return allowStyling();
      } else {
        return HtmlPolicyBuilder.this.allowAttributesGlobally(
            policy, attributeNames);
      }
    }

This construction used to work in version 20180219.1 of this library but is broken in 20211018.2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions