This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-xmlschema.git
The following commit(s) were added to refs/heads/master by this push:
new 647f77b7 Check that a relative schema location is a regular file (#168)
647f77b7 is described below
commit 647f77b7bdfafc570537e3b370720b9d4c88c61b
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Thu Sep 24 11:01:18 2026 +0100
Check that a relative schema location is a regular file (#168)
---
.../commons/schema/resolver/DefaultURIResolver.java | 8 +++++++-
.../src/test/java/tests/DefaultURIResolverTest.java | 20 ++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git
a/xmlschema-core/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
b/xmlschema-core/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
index 4329fc8b..7ad19405 100644
---
a/xmlschema-core/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
+++
b/xmlschema-core/src/main/java/org/apache/ws/commons/schema/resolver/DefaultURIResolver.java
@@ -236,6 +236,9 @@ public class DefaultURIResolver implements
CollectionURIResolver {
+ " working directory, which "
+ ALLOW_FILE_SYSTEM_PROPERTY + "
has turned off.");
}
+ // The parser opens this against the working directory, so it is
as much a local read
+ // as a file: URL and needs the same check.
+ verifyRegularFile(new File(schemaLocation), schemaLocation);
return new InputSource(schemaLocation);
}
return null;
@@ -572,7 +575,10 @@ public class DefaultURIResolver implements
CollectionURIResolver {
* @param schemaLocation the original schema location, for the error
message.
*/
private static void verifyRegularFile(String uri, String schemaLocation) {
- final File file = toLocalFile(uri);
+ verifyRegularFile(toLocalFile(uri), schemaLocation);
+ }
+
+ private static void verifyRegularFile(File file, String schemaLocation) {
if (file != null && file.exists() && !file.isFile()) {
throw new XmlSchemaException("The schema location \"" +
schemaLocation
+ "\" is not a regular file. A schema
document cannot be"
diff --git a/xmlschema-core/src/test/java/tests/DefaultURIResolverTest.java
b/xmlschema-core/src/test/java/tests/DefaultURIResolverTest.java
index ee150987..0d76ea21 100644
--- a/xmlschema-core/src/test/java/tests/DefaultURIResolverTest.java
+++ b/xmlschema-core/src/test/java/tests/DefaultURIResolverTest.java
@@ -454,6 +454,26 @@ public class DefaultURIResolverTest extends Assert {
assertSchemeRefused("jar:" + asFileUrl + "!/x.xsd", null, "not a
regular file");
}
+ /**
+ * With no base URI, a relative location is handed to the parser as-is and
opened against the
+ * working directory, so it is a local read like any file: URL and gets
the same check.
+ */
+ @Test
+ public void testARelativeLocationThatIsNotARegularFileIsRefused() {
+ assertTrue(new File(".").isDirectory());
+ assertSchemeRefused(".", null, "not a regular file");
+ }
+
+ @Test
+ public void testARelativeRegularOrMissingFileStillResolves() {
+ assertTrue(new File("pom.xml").isFile());
+ assertEquals("pom.xml",
+ new DefaultURIResolver().resolveEntity("urn:x",
"pom.xml", null).getSystemId());
+ assertEquals("no-such-schema.xsd",
+ new DefaultURIResolver()
+ .resolveEntity("urn:x", "no-such-schema.xsd",
null).getSystemId());
+ }
+
@Test
public void testARegularFileStillResolves() throws Exception {
File file = File.createTempFile("schema", ".xsd");