primefaces-extensions / primefaces-extensions

PrimeFaces Extensions
MIT License
112 stars 109 forks source link

SunEditor: Configure HtmlSanitizer to keep table styles #1580

Closed maroswal closed 1 month ago

maroswal commented 1 month ago

Describe the bug

In SunEditor you can set different table styles (min width, max width and fixed with) but the added style classes will be removed from the HtmlSanitizer.

table.se-table-size-100 {
   width: 100% !important;
}
table.se-table-size-auto {
   width: auto !important;
}
table.se-table-layout-fixed {
   width: fixed !important;
}

Reproducer

No response

Expected behavior

Either make the HtmlSanitizer somehow configurable or add table elements to the styles sanitizer to keep the applied table styles.

private static final PolicyFactory HTML_STYLES_SANITIZER = Sanitizers.STYLES
    .and(new HtmlPolicyBuilder()
        .allowElements("span", "li", "p", "pre", "div", "hr")
        .allowAttributes("class", "style", "contenteditable")
        .onElements("span", "li", "p", "pre", "div", "hr")
        .toFactory());

PrimeFaces Extensions version

13.0.11

JSF implementation

Mojarra

JSF version

2.3

Browser(s)

No response

melloware commented 1 month ago

Did you test will this fix it?

private static final PolicyFactory HTML_STYLES_SANITIZER = Sanitizers.STYLES
    .and(new HtmlPolicyBuilder()
        .allowElements("table", "span", "li", "p", "pre", "div", "hr")
        .allowAttributes("class", "style", "contenteditable")
        .onElements("table", "span", "li", "p", "pre", "div", "hr")
        .toFactory());
maroswal commented 1 month ago

Yes that's the way I fixed it with a monkey patch, but I haven't investigated if there are other elements with the same issue.

melloware commented 1 month ago

Nice i will add it. As a stopgap you can always set allowStyles="true" to turn off that 1 setting in the SunEditor.

maroswal commented 1 month ago

You're right, haven't thought about that option 😀

melloware commented 1 month ago

13.0.12 released