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 0b8d274c Check a file: location relative to the working directory as a
regular file (#184)
0b8d274c is described below
commit 0b8d274c6215fcc99ca41ad536eeff693cc49839
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Fri Sep 25 15:06:21 2026 +0100
Check a file: location relative to the working directory as a regular file
(#184)
---
.../schema/resolver/DefaultURIResolver.java | 5 +++++
.../test/java/tests/DefaultURIResolverTest.java | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+)
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 f9528777..d7c41f6d 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
@@ -622,6 +622,11 @@ public class DefaultURIResolver implements
CollectionURIResolver {
} catch (URISyntaxException e) {
return null;
}
+ if (parsed.isOpaque()) {
+ // "file:x", with no slash after the scheme, has no path as a URI,
but the JDK opens it
+ // as x in the working directory, as it does a relative location
with no base.
+ return relativeLocationFile(parsed.getRawSchemeSpecificPart());
+ }
try {
return new File(parsed);
} catch (IllegalArgumentException e) {
diff --git a/xmlschema-core/src/test/java/tests/DefaultURIResolverTest.java
b/xmlschema-core/src/test/java/tests/DefaultURIResolverTest.java
index 55eb7c4c..e3a2cd7b 100644
--- a/xmlschema-core/src/test/java/tests/DefaultURIResolverTest.java
+++ b/xmlschema-core/src/test/java/tests/DefaultURIResolverTest.java
@@ -476,6 +476,28 @@ public class DefaultURIResolverTest extends Assert {
assertSchemeRefused("src?query", null, "not a regular file");
}
+ /**
+ * "file:src", with no slash after the scheme, is an opaque URI with no
path, but the JDK opens
+ * it as src in the working directory, so it must be checked as that file.
+ */
+ @Test
+ public void testAFileLocationRelativeToTheWorkingDirectoryIsChecked() {
+ assertTrue(new File("src").isDirectory());
+ assertSchemeRefused("file:src", null, "not a regular file");
+ assertSchemeRefused("file:./src", null, "not a regular file");
+ assertSchemeRefused("FILE:src", null, "not a regular file");
+ assertSchemeRefused("file:sr%63?query", null, "not a regular file");
+ assertSchemeRefused("jar:file:src!/x.xsd", null, "not a regular file");
+ }
+
+ @Test
+ public void testAFileLocationRelativeToTheWorkingDirectoryStillResolves() {
+ assertTrue(new File("pom.xml").isFile());
+ assertEquals("file:pom.xml",
+ new DefaultURIResolver().resolveEntity("urn:x",
"file:pom.xml", null)
+ .getSystemId());
+ }
+
@Test
public void testARelativeRegularFileWithAFragmentStillResolves() {
assertEquals("pom.xml#fragment",