Browse Source

<xmlvalidate> ignored the encoding declaration of files it should

validate.

PR: 11279


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273582 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
0378839169
6 changed files with 56 additions and 8 deletions
  1. +3
    -0
      WHATSNEW
  2. +7
    -0
      src/etc/testcases/taskdefs/optional/xml/iso-2022-jp.xml
  3. +7
    -0
      src/etc/testcases/taskdefs/optional/xml/utf-8.xml
  4. +8
    -0
      src/etc/testcases/taskdefs/optional/xmlvalidate.xml
  5. +9
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
  6. +22
    -0
      src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java

+ 3
- 0
WHATSNEW View File

@@ -60,6 +60,9 @@ Fixed bugs:

* <concat> could append newline characters between concatenated files.

* <xmlvalidate> ignored the specified encoding of the files to
validate.

Other changes:
--------------
* The filesetmanifest attribute of <jar> has been reenabled.


+ 7
- 0
src/etc/testcases/taskdefs/optional/xml/iso-2022-jp.xml View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="iso-2022-jp"?>
<!DOCTYPE test [
<!ELEMENT test (#PCDATA)>
]>
<test>
ISO-2022-JP $B$N%U%!%$%k!#(B
</test>

+ 7
- 0
src/etc/testcases/taskdefs/optional/xml/utf-8.xml View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [
<!ELEMENT test (#PCDATA)>
]>
<test>
Liberté, égalité, fraternité!
</test>

+ 8
- 0
src/etc/testcases/taskdefs/optional/xmlvalidate.xml View File

@@ -73,4 +73,12 @@
</xmlvalidate>
</target>
<target name="testIso2022Jp">
<xmlvalidate warn="false" file="xml/iso-2022-jp.xml"/>
</target>

<target name="testUtf8">
<xmlvalidate warn="false" file="xml/utf-8.xml"/>
</target>

</project>

+ 9
- 8
src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java View File

@@ -54,7 +54,7 @@
package org.apache.tools.ant.taskdefs.optional;

import java.io.File;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -70,6 +70,7 @@ import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.XMLCatalog;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JAXPUtils;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
@@ -92,6 +93,11 @@ import org.xml.sax.helpers.ParserAdapter;
*/
public class XMLValidateTask extends Task {

/**
* helper for path -> URI and URI -> path conversions.
*/
private static FileUtils fu = FileUtils.newFileUtils();

protected static String INIT_FAILED_MSG =
"Could not start xml validation: ";

@@ -398,13 +404,8 @@ public class XMLValidateTask extends Task {
try {
log("Validating " + afile.getName() + "... ", Project.MSG_VERBOSE);
errorHandler.init(afile);
InputSource is = new InputSource(new FileReader(afile));
String uri = "file:" + afile.getAbsolutePath().replace('\\', '/');
for (int index = uri.indexOf('#'); index != -1;
index = uri.indexOf('#')) {
uri = uri.substring(0, index) + "%23"
+ uri.substring(index + 1);
}
InputSource is = new InputSource(new FileInputStream(afile));
String uri = fu.toURI(afile.getAbsolutePath());
is.setSystemId(uri);
xmlReader.parse(is);
} catch (SAXException ex) {


+ 22
- 0
src/testcases/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java View File

@@ -179,4 +179,26 @@ public class XmlValidateTest extends BuildFileTest {
}
}
}

/**
* iso-2022-jp.xml is valid but wouldn't get recognized on systems
* with a different native encoding.
*
* Bug 11279
*/
public void testIso2022Jp() {
executeTarget("testIso2022Jp");
}

/**
* utf-8.xml is invalid as it contains non-UTF-8 characters, but
* would pass on systems with a native iso-8859-1 (or similar)
* encoding.
*
* Bug 11279
*/
public void testUtf8() {
expectBuildException("testUtf8", "invalid characters in file");
}

}

Loading…
Cancel
Save