Menu

#216 elementNames(org.htmlcleaner.HtmlCleanerTest) test failure

v2.24
closed-fixed
nobody
None
5
2020-04-07
2019-09-09
niol
No

When running the test suite in 2.23, there is the following faillure.

[ERROR] elementNames(org.htmlcleaner.HtmlCleanerTest)  Time elapsed: 0.013 s  <<
< FAILURE!
org.junit.ComparisonFailure:
expected:<<p>
[<b></b>
]</p>> but was:<<p>
[            <b></b>
        ]</p>>
        at org.htmlcleaner.HtmlCleanerTest.elementNames(HtmlCleanerTest.java:227
)

Discussion

  • Scott Wilson

    Scott Wilson - 2019-09-09

    Well that's odd. It passes here locally, and it also passed during the release process (Maven always runs all unit tests during build and release).

     
  • niol

    niol - 2019-09-09

    I'm running the tests with java 11. Do you have any hint of where to look to understand this failure?

     
  • Scott Wilson

    Scott Wilson - 2019-09-09

    To some extent it depends on the implementation of the DOM interface installed on a specific system, which can vary. Its usually the Oracle/Sun one or Apache Xerces.

     
  • niol

    niol - 2019-09-11

    As this affects the default Transformer implementation in openjdk 11 (which does not seem to obey INDENT properties), I think this should be worked around.

    The following patch works around the issue.

    --- a/src/test/java/org/htmlcleaner/AbstractHtmlCleanerTest.java
    +++ b/src/test/java/org/htmlcleaner/AbstractHtmlCleanerTest.java
    @@ -100,7 +100,16 @@ public abstract class AbstractHtmlCleanerTest {
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.transform(new DOMSource(document), new StreamResult(writer));
    -       String actual = writer.getBuffer().toString();
    +       String rawActual = writer.getBuffer().toString();
    +
    +       String[] lines = rawActual.split("\n");
    +       StringWriter buffer = new StringWriter();
    +       for (String line: lines) {
    +           buffer.write(line.trim());
    +           buffer.write("\n");
    +       }
    +       String actual = buffer.toString();
    +
            actual = actual.substring(actual.indexOf("<body>\n")+7, actual.indexOf("</body>")).trim();
            assertEquals(expected, actual);
            cleaner.getProperties().setOmitHtmlEnvelope(true);
    
     
  • Scott Wilson

    Scott Wilson - 2019-09-11

    Thanks for the patch @niol - I did wonder if this was related to OpenJDK.

     
  • Scott Wilson

    Scott Wilson - 2020-04-07

    Patch applied, it'll be in the next release.

     
  • Scott Wilson

    Scott Wilson - 2020-04-07
    • status: open --> closed-fixed
    • Group: v 2.7 --> v2.24
     

Log in to post a comment.

MongoDB Logo MongoDB