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

bug: indentify the bug with XMLDocument comparison #247

Merged
merged 8 commits into from
May 24, 2024

Conversation

volodya-lombrozo
Copy link
Contributor

@volodya-lombrozo volodya-lombrozo commented May 3, 2024

I have faced with the problem of XMLDocument comparison. If there are two similar documents, but with different formatting, they aren't equal to each other. For example:

<program>
  <indentation/>
</program>

and

<program>
    <indentation/>
</program>

aren't equal XMLDocuments.

In this PR I added:

  1. The unit test that reveals the problem with XMLDocument comparison
  2. The integration test that uses XMLDocument in a Groovy script (the place where I originally have found the bug).

@volodya-lombrozo
Copy link
Contributor Author

@yegor256 Could you take a look, please?

@yegor256
Copy link
Member

yegor256 commented May 3, 2024

@volodya-lombrozo well, technically, these are two different documents. In XML, spaces are not ignored - they are part of the syntax. The following document:

<a> <b/>  </a>

Is parsed into:

Element("a", [Text(" "), Element("b", []), Text("  ")])`

I'm not sure jcabi-xml should ignore all spaces (which are Text elements and may be important).

@volodya-lombrozo
Copy link
Contributor Author

@yegor256 , what if we add one more document type, XmlDocumentTrimmed? There is definitely a request from the community:

Moreover, I've faced with the same problem myself. I want to compare two XMLs indecently on their formatting.

@volodya-lombrozo
Copy link
Contributor Author

@yegor256 what do you think?

yegor256 added a commit that referenced this pull request May 6, 2024
@yegor256
Copy link
Member

yegor256 commented May 6, 2024

@volodya-lombrozo I tried to reproduce the bug in 818f3ea, but failed. Can you suggest a unit test that will show the problem?

yegor256 added a commit that referenced this pull request May 6, 2024
yegor256 added a commit that referenced this pull request May 6, 2024
yegor256 added a commit that referenced this pull request May 6, 2024
yegor256 added a commit that referenced this pull request May 6, 2024
@volodya-lombrozo
Copy link
Contributor Author

@yegor256 Yes, you are right. My unit test doesn't reproduce the error. However, the integration test does. You can run it using the following command:

mvn clean integration-test invoker:run -Dinvoker.test=groovy -DskipTests

Does this test causes error in your environment?

@volodya-lombrozo
Copy link
Contributor Author

@yegor256 I tried to mimic the same code in Java:

final File first = Paths.get("/absolute-path-to/first.xmir").toFile();
final File same = Paths.get("/absolute-path-to/same.xmir").toFile();
MatcherAssert.assertThat(
     new XMLDocument(first),
     Matchers.equalTo(new XMLDocument(same))
);

And it passes successfully. Most probably, this problem is groovy - specific.

@volodya-lombrozo
Copy link
Contributor Author

@yegor256, I have finally identified the problem. In the unit tests, we use net.sf.saxon.jaxp.IdentityTransformer to convert XMLDocument into a String. In the integration tests, we use com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl to convert XMLDocument into a String. XMLDocument uses strings to compare itself with another XMLDocument.

I have demonstrated this case in the unit test. Could you please take a look one more time?

@volodya-lombrozo
Copy link
Contributor Author

@yegor256 What do you think?

@yegor256
Copy link
Member

@rultor merge

@rultor
Copy link
Contributor

rultor commented May 24, 2024

@rultor merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 2107ecf into jcabi:master May 24, 2024
8 checks passed
@rultor
Copy link
Contributor

rultor commented May 24, 2024

@rultor merge

@yegor256 Done! FYI, the full log is here (took me 12min)

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

Successfully merging this pull request may close these issues.

3 participants