Commit cffce2ec authored by Pakulin's avatar Pakulin
Browse files

Fixed a bug with non-ASCII characters in element names.

Added regression tests
parent 1a718cbc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<ns:MyType日本 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns="schema:Pos_050202_name_conversion_rules_014">1.0</ns:MyType日本>
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
  targetNamespace="schema:Pos_050202_name_conversion_rules_014"
  xmlns:ns="schema:Pos_050202_name_conversion_rules_014">
  <element name="MyType" type="integer" />
  <element name="MyType中国" type="string" />
  <element name="MyType日本" type="float" />
</schema>
+2 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<ns1:MyType日本 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="schema:Pos_050202_name_conversion_rules_014">1.000000E+000</ns1:MyType日本>
 No newline at end of file
+6 −2
Original line number Diff line number Diff line
@@ -167,9 +167,13 @@ public class DifferenceHandler implements DifferenceListener {
	//@Override
	public void skippedComparison(Node control, Node test) {
	}
	
	// Transform XPath from /nodename[1]/ to /[local-name()='nodename'/
	// The reason is that the order of nodes is not strictly defined in an XML document due to . 
	private static String fixXpath(String orig) {
		String result = orig.replaceAll("/([a-zA-Z0-9_-]+)(\\[[0-9]+\\](/|$))?", "/*[local-name()='$1']$2");
		// This regular expression is invalid: it fails on names like ns1:MyType日本
		// String result = orig.replaceAll("/([a-zA-Z0-9_-]+)(\\[[0-9]+\\](/|$))?", "/*[local-name()='$1']$2");
		// Simplified regex: (any character distinct from [)+ 
		String result = orig.replaceAll("/([^\\[/]+)(\\[[0-9]+\\](/|$))?", "/*[local-name()='$1']$2");
		XmlDiff.logger.debug2("Original xpath: {", orig, "}, modified: {", result, "}");
		return result;
	}
+1 −1
Original line number Diff line number Diff line
@@ -176,7 +176,7 @@ public class XmlDiff {
	 * @return
	 * @throws XmlDiffError
	 */
	boolean diff(Reader input, StringBuilder diffDetails) throws XmlDiffError {
	public boolean diff(Reader input, StringBuilder diffDetails) throws XmlDiffError {
		InputStream stream;
		try {
			stream = new FileInputStream(referenceXmlFile);
Loading