From: SourceForge.net <no...@so...> - 2008-01-04 20:03:39
|
Bugs item #1863632, was opened at 2008-01-03 15:05 Message generated for change (Comment added) made by forestcarlisle You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1863632&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Pending Resolution: Works For Me Priority: 5 Private: No Submitted By: Forest (forestcarlisle) Assigned to: Nobody/Anonymous (nobody) Summary: similar ignore-whitespace comparison fails incorrectly Initial Comment: consider the following control xml <a><b/></a> vs. the following test xml <a> <b/> </a> when XMLUnit has been configured to ignore whitespace by XMLUnit.setIgnoreWhitespace(true). if we are ignoring whitespace, then these two documents should be similar. on line 305 of DifferenceEngine.class for v1.1, the diff compares the number of child nodes of <a> and finds that the control xml has 1 child node and the test xml has 3 child nodes. the extra 2 child nodes on the text xml are whitespace-only, but this causes a DifferenceFoundException to be thrown simply because the count is different. this logic is too limited; it should only be thrown when whitespace is *not* being ignored. the fix is to first eliminate any all-whitespace nodes from the node list when ignoring whitespace *unless* the node has exactly one child node. in the latter case, the single child node can be a text node with whitespace which should be regarded as literal text, as in the following example: <a><b> </b></a> is not similar to <a><b/></a> ---------------------------------------------------------------------- Comment By: Forest (forestcarlisle) Date: 2008-01-04 12:03 Message: Logged In: YES user_id=1092645 Originator: YES You actually need to have a namespace variable on the root element (or any child element) to see the problem. Sorry about that. public void testBasicWhitespaceHandling() throws Exception { String control = "<xyz:a xmlns:xyz=\"abc\"><b/></xyz:a>"; String test = "<xyz:a xmlns:xyz=\"abc\">\r\n <b/>\r\n</xyz:a>"; XMLUnit.setIgnoreWhitespace(true); try { Diff diff = XMLUnit.compareXML(control, test); assert diff.similar() : diff.toString(); } finally { XMLUnit.setIgnoreWhitespace(false); } } ---------------------------------------------------------------------- Comment By: Stefan Bodewig (bodewig) Date: 2008-01-04 01:42 Message: Logged In: YES user_id=113148 Originator: NO there must be some other problem with your test since not only are the two pieces similar, they are even identical. I've just added a testcase for your report http://xmlunit.svn.sourceforge.net/viewvc/xmlunit/trunk/?view=log and it passes. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377768&aid=1863632&group_id=23187 |