Skip to content

style attribute "margin" property is missing fourth element after sanitizing #183

Closed
@janis-github

Description

@janis-github

The margin property is missing left alignment value after sanitisation.

Here is the code:

     private static final CssSchema MY_CSSSCHEMA = CssSchema.withProperties(ImmutableSet.of(
          "margin",
          "list-style-type",
          "vertical-align"
  ));

   PolicyFactory policy = new HtmlPolicyBuilder()
        .allowAttributes("class")
        .onElements("li")
        .allowAttributes("checked", "type")
        .onElements("input")
        .allowElements("i", "u", "b", "p", "pre", "blockquote", "tt", "em", "ul", "ol", "br", "li", "sub", "sup", "div",
            "table", "img", "a", "tbody", "tr", "td", "strong", "span", "h1", "h2", "h3", "code", "md", "video",
            "source", "th", "thead", "h4", "h5", "h6", "h7", "h8", "h9", "h10", "h11", "hr")
        .allowStyling(MY_CSSSCHEMA)
        .toFactory();
    String postSanitize = policy.sanitize(text).trim();

This is my input string:

<ul>
<li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked> This is a complete item</li>
<li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"> This is an incomplete item</li>
</ul>

Here is the output:

<ul><li class="task-list-item"><input type="checkbox" style="margin:0px 0.35em 0.25em" checked="checked" disabled="1" /> This is a complete item</li><li class="task-list-item"><input type="checkbox" style="margin:0px 0.35em 0.25em" disabled="1" /> This is an incomplete item</li></ul>

Note that

style="margin:0px 0.35em 0.25em"

but it should be:

style="margin: 0px 0.35em 0.25em -1.6em"

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