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

Whitespaces are not correctly compared #30

Open
SimplyComple0x78 opened this issue Dec 1, 2017 · 2 comments
Open

Whitespaces are not correctly compared #30

SimplyComple0x78 opened this issue Dec 1, 2017 · 2 comments

Comments

@SimplyComple0x78
Copy link

SimplyComple0x78 commented Dec 1, 2017

I would expect the module to identify some xml only as equal, if their contents with text-contents and their whitespaces are really the same.
It seems that the module does ignore it, if the one XML has got some spaces somewhere and the other has got a differenz amount of spaces or none at all.

const dom = require('xmldom').DOMParser;
const xmlSerializer = require('xmldom').XMLSerializer;
const compare = require('dom-compare').compare;


const xmlA = new dom().parseFromString("<foo> </foo>");
const xmlB = new dom().parseFromString("<foo></foo>");
const xmlC = new dom().parseFromString("<foo> a</foo>");

console.log(new xmlSerializer().serializeToString(xmlA));
console.log(new xmlSerializer().serializeToString(xmlB));

const resultAB = compare(xmlA, xmlB); //empty diff, but should contain " '    ' is not ' ' "
const resultBC = compare(xmlB, xmlC); //non-empty diff, because " " is not " a" what is correct

console.log(resultAB);
console.log(resultBC);

"stripSpaces" should be false as default so I don't know what to do to achieve this.

@Olegas
Copy link
Owner

Olegas commented Aug 26, 2018

Why do you need this? What is the task?
xmlA and xmlB are the same from the XML point of view, isn't it?

@SimplyComple0x78
Copy link
Author

SimplyComple0x78 commented Aug 27, 2018

Hey @Olegas,
the tool compares XML including characters, so why not space-characters? I agree that it's kind of an edge-case, but I thought "stripSpaces=false" would do exactly this.

In my use-case, I fiddle around with XML and HTML, basically rendering XML as HTML, and I use your tool in automated tests to verify whether XMLs are correct at some point.
Sadly, in the HTML-output there's a huge difference between <p>a <span>b</span></p>, which renders like a b and the variant without a space <p>a<span>b</span></p> which renders like ab.

We found the bug when looking at the broken output while the tests still passed.
Any idea on how to achieve this kind of comparison though?

Best wishes

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

2 participants