Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
janis-github opened this issue Sep 4, 2019 · 1 comment

Comments

@janis-github
Copy link

janis-github commented Sep 4, 2019

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"
@janis-github
Copy link
Author

Turns out that this is about "margin" token value being negative. Created PR184 for fixing that. Closing the issue in favour of PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant