Uploaded image for project: 'Hippo CMS'
  1. Hippo CMS
  2. CMS-9563

current configuration of HtmlCleaner strips <style> elements when setting htmlcleaner.id to empty

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • 3.0.1
    • 3.2.6, 4.0.4, 4.1.0
    • None
    • None
    • Pulsar

    Description

      According to the documentation (link) setting htmlcleaner.id to an empty string or removing the property altogether should have the functional effect that all incoming HTML is preserved. As a result of the refactoring done in CMS-1610 and CMS-8638 the HtmlCleaner is now also invoked to rewrite the metadata saved for links. As part of this fix make update the aforementioned documentation page to state the functional effect rather than the implementation and fix the problem that the current configuration strips <style> elements.

      The current configuration of HtmlCleaner currently strips out <style> elements. This can be reproduced by adding the following test case to org.hippoecm.frontend.plugins.richtext.htmlcleaner.HtmlCleanerPluginTest

          @Test
          public void testStyle() throws Exception {
              final HtmlCleanerPlugin htmlCleanerPlugin = new HtmlCleanerPlugin(null, getPluginConfig());
      
              String html = htmlCleanerPlugin.clean("<style>h1 {color:black;}</style>");
              assertEquals("<style>h1 {color:black;}</style>", html);
          }
      

      When checking out the actual HtmlCleaner project, adding the following unit test to org.htmlcleaner.HtmlCleanerTest will pass.

          @Test
          public void styleElement() throws Exception {
              assertCleaned(
                      "<style>h1 {color:black;}</style>",
                      "<html>\n" +
                              "<head><style>/*<![CDATA[*/\n" +
                              "h1 {color:black;}\n" +
                              "/*]]>*/</style></head>\n" +
                              "<body /></html>"
              );
          }
      

      A newer version of HtmlCleaner is also available (2.14), bumping the dependency to that version does not fix the problem.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              oscholten Oscar Scholten (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: