This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new 000964618 Fix Windows path with drive letter lost in 
RepositoryUriUtils.basedir() (#2224)
000964618 is described below

commit 0009646186857d4b6daba65e794cbb084b9aec94
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Nov 3 21:32:41 2026 +0100

    Fix Windows path with drive letter lost in RepositoryUriUtils.basedir() 
(#2224)
    
    * Fix Windows path with drive letter lost in RepositoryUriUtils.basedir()
    
    RepositoryUriUtils.basedir() treated the Windows drive letter (e.g. "C")
    as a URL scheme and stripped it along with the trailing ":", producing
    a drive-relative path ("\Users\...") instead of an absolute path.
    Path.of("\Users\...").toUri() then resolved against the JVM working
    directory, which can be on a different drive on Windows CI runners
    (e.g. D: instead of C:), causing path mismatches.
    
    Fix: detect single uppercase-letter "protocols" in basedir() and return
    the original URL unchanged (the drive letter is not a protocol prefix).
    Also switch from new File(path).toUri() to Paths.get(path).toUri() in
    toUri() so that path parsing is fully lexical and never involves File's
    working-directory-relative resolution.
    
    Adds a Windows-only test reproducing the bug.
    
    * Fix Windows CI: use URI-based Paths.get() for file: URLs, support 
lowercase drive letters
    
    - toUri(): split the 'file:' case to use Paths.get(URI.create(url)) which
      handles percent-encoding and Windows paths like file:/D:/a/... correctly
      without triggering InvalidPathException on Windows (the previous
      Paths.get(basedir(url)) call received '/D:/a/...' which is illegal on 
Windows)
    - isWindowsDriveLetter(): extracted helper, now detects both uppercase and
      lowercase drive letters (Character.isLetter, no isUpperCase restriction)
    - basedir(): updated to use isWindowsDriveLetter() for consistency
    - Add RepositoryUriUtilsTest covering file: URLs, plain Windows paths
      (uppercase/lowercase/forward-slash), Unix paths and https: pass-through;
      runs on all platforms without OS restrictions
    - LocalRepositoryTest: replace windowsPlainPathPreservesDriveLetter with 
three
      focused Windows-only tests; use java.io.tmpdir for the drive letter (no
      hardcoded username), Path equality for round-trip, Character.toUpperCase()
      for locale-independent comparison; add lowercase and forward-slash 
variants
    
    * Fix RepositoryUriUtilsTest.fileUrlUnixPath: don't assert path on Windows
    
    On Windows, Paths.get(URI.create('file:///home/user/repo')) prepends the
    current drive letter, so the path assertion failed. Only assert the scheme,
    which is the cross-platform invariant.
    
    * Fix Windows CI: normalize file:/X:/... to file:///X:/... before 
Paths.get(URI)
    
    On Windows, Paths.get(URI) calls WindowsPath.parse() with the URI path
    component. For file:/D:/a/... URIs (single-slash, produced by File.toURI()
    on Windows runners), the path component is /D:/a/... which Windows rejects
    with InvalidPathException: Illegal char <:>.
    
    The RFC 8089 triple-slash form file:///D:/... has an empty authority
    component, and the JDK strips the leading '/' when authority is empty,
    giving D:/... which is a valid Windows path.
    
    Fix: before calling Paths.get(URI.create(...)), normalize single-slash
    file URIs to the triple-slash form.
    
    * fix: handle opaque/authority file: URLs and unencoded spaces in 
RepositoryUriUtils.toUri()
    
    The previous implementation used URI.create() directly on the repository 
URL,
    which fails for:
    - Opaque file: URLs (file:repo) - URI.create works but Paths.get(opaque 
URI) throws
      'URI is not hierarchical'
    - Unencoded spaces (file:repo space, file:/repo space) - URI.create() throws
      URISyntaxException
    - Authority-bearing URLs (file://host/path) - Paths.get(URI) throws
      'URI has an authority component' on Unix
    
    Fix: use basedir() to extract and normalize the path from any file: URL 
form,
    then rebuild a proper file: URI using the multi-arg URI constructor (which
    percent-encodes the path automatically). For relative paths (from opaque 
URLs),
    use Paths.get(String).toAbsolutePath(). For absolute/Windows drive-letter 
paths,
    use new URI("file", "", path, null, null) to get the three-slash form
    (file:///path) that Paths.get(URI) handles correctly on all platforms.
    
    * nit: restrict isWindowsDriveLetter to ASCII letters only
    
    Character.isLetter() is Unicode-aware and would return true for non-ASCII
    letters (e.g. accented characters). Use an explicit ASCII range check
    instead to match only valid Windows drive letters A-Z / a-z.
    
    * nit: annotate Windows-path tests with @EnabledOnOs(OS.WINDOWS)
    
    On Linux, Paths.get("C:\\Users\\...") treats backslash as a regular
    character and produces a relative path, so the drive-letter assertions
    would pass vacuously via an encoded path match rather than testing the
    actual drive-letter branch. Restrict these three tests to Windows only.
    
    Tests using file: URLs are correct on all platforms and remain unannotated.
    
    * test: add regression tests for file: URLs with spaces
    
    Add three tests to RepositoryUriUtilsTest suggested in the review:
    - fileUrlOpaqueWithUnencodedSpace: file:repo space (must not throw)
    - fileUrlHierarchicalWithUnencodedSpace: file:/repo space (must not throw)
    - fileUrlWithPercentEncodedSpace: file:repo%20space (must decode space)
    
    These guard against regressions in the multi-arg URI constructor path
    introduced to handle Windows drive letters correctly.
    
    * test: pick a different drive from CWD in Windows drive-letter tests
    
    The regression guard requires the test drive to differ from the JVM
    working-directory drive. When they are the same, the original bug
    (strip drive letter → drive-relative path → resolve against CWD)
    produces the correct result by coincidence, so the test passes even
    without the fix.
    
    Use FileSystems.getDefault().getRootDirectories() to find a drive other
    than the CWD drive, falling back to the CWD drive only when there is a
    single drive available. Applies the same change to all three Windows-
    path tests (uppercase, lowercase, forward-slash) for consistency.
---
 .../aether/repository/RepositoryUriUtils.java      |  58 +++++-
 .../aether/repository/LocalRepositoryTest.java     | 111 ++++++++++++
 .../aether/repository/RepositoryUriUtilsTest.java  | 195 +++++++++++++++++++++
 3 files changed, 357 insertions(+), 7 deletions(-)

diff --git 
a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryUriUtils.java
 
b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryUriUtils.java
index 6d720e066..cd1c1e403 100644
--- 
a/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryUriUtils.java
+++ 
b/maven-resolver-api/src/main/java/org/eclipse/aether/repository/RepositoryUriUtils.java
@@ -18,8 +18,9 @@
  */
 package org.eclipse.aether.repository;
 
-import java.io.File;
 import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
 
 /**
  * URL handling for file URLs. Based on org.apache.maven.wagon.PathUtils.
@@ -39,11 +40,35 @@ public final class RepositoryUriUtils {
      */
     public static URI toUri(String repositoryUrl) {
         final String protocol = protocol(repositoryUrl);
-        if ("file".equals(protocol)
-                || protocol.isEmpty()
-                || protocol.length() == 1
-                        && (Character.isLetter(protocol.charAt(0)) && 
Character.isUpperCase(protocol.charAt(0)))) {
-            return new File(basedir(repositoryUrl)).toURI();
+        if ("file".equals(protocol)) {
+            // Use basedir() to normalize and extract the path from any file: 
URL form:
+            //   opaque (file:repo), with authority (file://host/path), 
unencoded spaces,
+            //   percent-encoded spaces, Windows drive letters (file:/C:/..., 
file:///C:/...).
+            // Then rebuild a well-formed file: URI using the multi-arg URI 
constructor
+            // (which percent-encodes the path automatically), and pass it to 
Paths.get(URI)
+            // so that Windows drive-letter handling is done by the JDK.
+            String path = basedir(repositoryUrl);
+            try {
+                URI uri;
+                if (path.isEmpty()
+                        || (!path.startsWith("/") && 
!isWindowsDriveLetter(String.valueOf(path.charAt(0))))) {
+                    // Relative path (e.g. from opaque file:repo): resolve 
against cwd via Paths.get(String)
+                    return Paths.get(path).toAbsolutePath().toUri();
+                }
+                // Absolute path or Windows drive letter path.
+                // Use authority="" to produce file:///path (three-slash form) 
which Paths.get(URI)
+                // handles correctly on Windows: the JDK treats the empty 
authority as localhost
+                // and strips the leading '/' before a Windows drive letter 
(e.g. /C:/... → C:/...).
+                uri = new URI("file", "", path, null, null);
+                return Paths.get(uri).toUri();
+            } catch (URISyntaxException e) {
+                // Should not happen since basedir() returns a clean path; 
fall back to string-based parse
+                return Paths.get(path).toUri();
+            }
+        } else if (protocol.isEmpty() || isWindowsDriveLetter(protocol)) {
+            // Use Paths.get() to parse the local path lexically, without 
resolving against the JVM
+            // working directory via File (which may be on a different drive 
on Windows).
+            return Paths.get(basedir(repositoryUrl)).toUri();
         } else {
             return URI.create(repositoryUrl);
         }
@@ -76,7 +101,13 @@ public final class RepositoryUriUtils {
         String retValue;
 
         if (!protocol.isEmpty()) {
-            retValue = url.substring(protocol.length() + 1);
+            // A single letter (case-insensitive) is a Windows drive letter 
(e.g. "C:\path" or "c:\path"),
+            // not a URL scheme. Keep it in the path; do not strip it as if it 
were a protocol prefix.
+            if (isWindowsDriveLetter(protocol)) {
+                retValue = url;
+            } else {
+                retValue = url.substring(protocol.length() + 1);
+            }
         } else {
             retValue = url;
         }
@@ -113,6 +144,19 @@ public final class RepositoryUriUtils {
         return retValue.trim();
     }
 
+    /**
+     * Returns {@code true} if the given protocol token is a single ASCII 
letter, which on Windows indicates
+     * a drive letter (e.g. {@code C} in {@code C:\\path} or {@code c} in 
{@code c:/path}) rather than a URL scheme.
+     * The check is restricted to ASCII letters only (not Unicode letters) and 
is locale-independent.
+     */
+    private static boolean isWindowsDriveLetter(String protocol) {
+        if (protocol.length() != 1) {
+            return false;
+        }
+        char c = protocol.charAt(0);
+        return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
+    }
+
     /**
      * Decodes the specified (portion of a) URL. <strong>Note:</strong> This 
decoder assumes that ISO-8859-1 is used to
      * convert URL-encoded octets to characters.
diff --git 
a/maven-resolver-api/src/test/java/org/eclipse/aether/repository/LocalRepositoryTest.java
 
b/maven-resolver-api/src/test/java/org/eclipse/aether/repository/LocalRepositoryTest.java
index ce45c8cbf..ecf48d71d 100644
--- 
a/maven-resolver-api/src/test/java/org/eclipse/aether/repository/LocalRepositoryTest.java
+++ 
b/maven-resolver-api/src/test/java/org/eclipse/aether/repository/LocalRepositoryTest.java
@@ -20,8 +20,15 @@ package org.eclipse.aether.repository;
 
 import java.io.File;
 import java.nio.file.FileSystems;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.stream.StreamSupport;
 
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class LocalRepositoryTest {
     @Test
@@ -49,4 +56,108 @@ public class LocalRepositoryTest {
     private void doIt(File file) {
         new LocalRepository(file.toPath().toUri().toASCIIString());
     }
+
+    /**
+     * Verifies that a plain Windows path string with an uppercase drive 
letter (e.g. {@code C:\Users\foo\repo})
+     * passed to {@link LocalRepository#LocalRepository(String)} preserves the 
drive letter and does not
+     * resolve against the JVM working directory. Previously, {@code 
RepositoryUriUtils.basedir()}
+     * treated the drive letter as a URL scheme and stripped it, producing a 
drive-relative path
+     * ({@code \Users\foo\repo}) that {@code new File(...).toURI()} then 
resolved against the JVM
+     * working directory — which can be on a different drive on Windows CI 
runners.
+     *
+     * <p>The test deliberately picks a drive letter <em>different</em> from 
the JVM working directory.
+     * This is essential for the regression guard: if the drive letter were 
the same as the CWD drive,
+     * the old bug (strip drive → drive-relative path → resolve against CWD) 
would still produce the
+     * correct result and the test would pass without detecting the bug.
+     */
+    @Test
+    @EnabledOnOs(OS.WINDOWS)
+    void windowsPlainPathUppercaseDriveLetterPreserved() {
+        // Pick a drive that is NOT the CWD drive to detect the cross-drive 
regression reliably.
+        char cwdDrive = Character.toUpperCase(
+                Paths.get("").toAbsolutePath().getRoot().toString().charAt(0));
+        char driveLetter = StreamSupport.stream(
+                        
FileSystems.getDefault().getRootDirectories().spliterator(), false)
+                .map(p -> Character.toUpperCase(p.toString().charAt(0)))
+                .filter(c -> c != cwdDrive)
+                .findFirst()
+                .orElse(cwdDrive); // fall back to CWD drive if there is only 
one drive
+        String plainPath = driveLetter + ":\\test-resolver-repo\\my-repo";
+
+        LocalRepository repo = new LocalRepository(plainPath);
+        Path basePath = repo.getBasePath();
+
+        // The resolved path must start with the same drive letter 
(locale-independent comparison).
+        assertEquals(
+                driveLetter,
+                Character.toUpperCase(basePath.toString().charAt(0)),
+                "Drive letter must be preserved when parsing a plain Windows 
path: " + basePath);
+        // The full absolute path must round-trip unchanged.
+        assertEquals(
+                Paths.get(plainPath),
+                basePath,
+                "Plain Windows path must round-trip through 
LocalRepository(String) unchanged");
+    }
+
+    /**
+     * Verifies that a plain Windows path string with a <em>lowercase</em> 
drive letter (e.g. {@code c:\Users\foo\repo})
+     * is also handled correctly. Before the fix, only uppercase drive letters 
were detected.
+     *
+     * <p>Picks a drive different from the CWD drive for the same reason as
+     * {@link #windowsPlainPathUppercaseDriveLetterPreserved()}.
+     */
+    @Test
+    @EnabledOnOs(OS.WINDOWS)
+    void windowsPlainPathLowercaseDriveLetterPreserved() {
+        char cwdDrive = Character.toUpperCase(
+                Paths.get("").toAbsolutePath().getRoot().toString().charAt(0));
+        char upperDrive = StreamSupport.stream(
+                        
FileSystems.getDefault().getRootDirectories().spliterator(), false)
+                .map(p -> Character.toUpperCase(p.toString().charAt(0)))
+                .filter(c -> c != cwdDrive)
+                .findFirst()
+                .orElse(cwdDrive);
+        char lowerDrive = Character.toLowerCase(upperDrive);
+        String plainPath = lowerDrive + ":\\test-resolver-repo\\my-repo";
+
+        LocalRepository repo = new LocalRepository(plainPath);
+        Path basePath = repo.getBasePath();
+
+        assertEquals(
+                upperDrive,
+                Character.toUpperCase(basePath.toString().charAt(0)),
+                "Drive letter must be preserved for lowercase input: " + 
basePath);
+        assertEquals(
+                Paths.get(plainPath),
+                basePath,
+                "Lowercase drive-letter path must round-trip through 
LocalRepository(String) unchanged");
+    }
+
+    /**
+     * Verifies that a Windows path with forward slashes (e.g. {@code 
C:/Users/foo/repo}) is handled correctly.
+     *
+     * <p>Picks a drive different from the CWD drive for the same reason as
+     * {@link #windowsPlainPathUppercaseDriveLetterPreserved()}.
+     */
+    @Test
+    @EnabledOnOs(OS.WINDOWS)
+    void windowsPlainPathForwardSlashPreserved() {
+        char cwdDrive = Character.toUpperCase(
+                Paths.get("").toAbsolutePath().getRoot().toString().charAt(0));
+        char driveLetter = StreamSupport.stream(
+                        
FileSystems.getDefault().getRootDirectories().spliterator(), false)
+                .map(p -> Character.toUpperCase(p.toString().charAt(0)))
+                .filter(c -> c != cwdDrive)
+                .findFirst()
+                .orElse(cwdDrive);
+        String plainPath = driveLetter + ":/test-resolver-repo/my-repo";
+
+        LocalRepository repo = new LocalRepository(plainPath);
+        Path basePath = repo.getBasePath();
+
+        assertEquals(
+                driveLetter,
+                Character.toUpperCase(basePath.toString().charAt(0)),
+                "Drive letter must be preserved for forward-slash Windows 
path: " + basePath);
+    }
 }
diff --git 
a/maven-resolver-api/src/test/java/org/eclipse/aether/repository/RepositoryUriUtilsTest.java
 
b/maven-resolver-api/src/test/java/org/eclipse/aether/repository/RepositoryUriUtilsTest.java
new file mode 100644
index 000000000..3bb7c8f5c
--- /dev/null
+++ 
b/maven-resolver-api/src/test/java/org/eclipse/aether/repository/RepositoryUriUtilsTest.java
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eclipse.aether.repository;
+
+import java.net.URI;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests for {@link RepositoryUriUtils#toUri(String)}, focusing on Windows 
drive-letter handling.
+ * Tests that pass plain Windows paths (with backslash or {@code X:} prefix) 
are
+ * {@link EnabledOnOs @EnabledOnOs(OS.WINDOWS)} because on Linux {@code 
Paths.get("C:\\...")}
+ * treats the input as a relative path (backslash is not a separator), 
producing a wrong URI
+ * that could accidentally satisfy the drive-letter assertion.
+ * Tests that pass {@code file:} URLs are safe to run on all platforms.
+ */
+public class RepositoryUriUtilsTest {
+
+    /**
+     * A plain Windows path with an uppercase drive letter must produce a 
{@code file:} URI
+     * whose path starts with the drive letter, not a relative path missing 
the drive.
+     * <p>Restricted to Windows because on Linux {@code Paths.get("C:\\...")} 
is a relative path.</p>
+     */
+    @Test
+    @EnabledOnOs(OS.WINDOWS)
+    void windowsUppercaseDriveLetterPreserved() {
+        URI uri = RepositoryUriUtils.toUri("C:\\Users\\foo\\repo");
+        assertEquals("file", uri.getScheme());
+        // The path component must contain the drive letter
+        String path = uri.getSchemeSpecificPart();
+        assertContainsDriveLetter('C', path);
+    }
+
+    /**
+     * A plain Windows path with a lowercase drive letter must also be handled 
correctly.
+     * Before the fix, only uppercase letters were detected as drive letters.
+     * <p>Restricted to Windows because on Linux {@code Paths.get("c:\\...")} 
is a relative path.</p>
+     */
+    @Test
+    @EnabledOnOs(OS.WINDOWS)
+    void windowsLowercaseDriveLetterPreserved() {
+        URI uri = RepositoryUriUtils.toUri("c:\\Users\\foo\\repo");
+        assertEquals("file", uri.getScheme());
+        String path = uri.getSchemeSpecificPart();
+        assertContainsDriveLetter('c', path);
+    }
+
+    /**
+     * A Windows path with forward slashes must also be handled correctly.
+     * <p>Restricted to Windows because {@code C:/...} is parsed as a URL 
scheme on Linux
+     * ({@code "C"} would be the protocol), which takes a different code 
path.</p>
+     */
+    @Test
+    @EnabledOnOs(OS.WINDOWS)
+    void windowsDriveLetterForwardSlash() {
+        URI uri = RepositoryUriUtils.toUri("C:/Users/foo/repo");
+        assertEquals("file", uri.getScheme());
+        String path = uri.getSchemeSpecificPart();
+        assertContainsDriveLetter('C', path);
+    }
+
+    /**
+     * A {@code file:} URL with a Windows drive letter (as produced by Windows 
CI runners)
+     * must be converted without an {@code InvalidPathException}. This was the 
root cause of the
+     * CI failures: {@code file:/D:/a/...} was passed through {@code new 
File(...).toURI()} which
+     * resolved against the JVM working directory when the drive letters 
differed.
+     */
+    @Test
+    void fileUrlWithWindowsDriveLetter() {
+        // This is the URL format that Windows GitHub Actions runners produce
+        URI uri = RepositoryUriUtils.toUri("file:/C:/Users/test/repo");
+        assertEquals("file", uri.getScheme());
+        String path = uri.getSchemeSpecificPart();
+        assertContainsDriveLetter('C', path);
+    }
+
+    /**
+     * A {@code file:///} URL (three slashes, standard RFC 8089 form) with a 
Windows drive letter.
+     */
+    @Test
+    void fileUrlTripleSlashWithWindowsDriveLetter() {
+        URI uri = RepositoryUriUtils.toUri("file:///C:/Users/test/repo");
+        assertEquals("file", uri.getScheme());
+        String path = uri.getSchemeSpecificPart();
+        assertContainsDriveLetter('C', path);
+    }
+
+    /**
+     * A Unix absolute path must round-trip unchanged.
+     */
+    @Test
+    void unixAbsolutePath() {
+        URI uri = RepositoryUriUtils.toUri("/home/user/repo");
+        assertEquals("file", uri.getScheme());
+    }
+
+    /**
+     * A {@code file:} URL with a Unix path must be converted to a file: URI.
+     * Note: on Windows, Paths.get(URI) for a Unix-style path will resolve 
against
+     * the current drive, so we only assert the scheme here.
+     */
+    @Test
+    void fileUrlUnixPath() {
+        URI uri = RepositoryUriUtils.toUri("file:///home/user/repo");
+        assertEquals("file", uri.getScheme());
+    }
+
+    /**
+     * A non-file URL (e.g. {@code https:}) must be returned as-is.
+     */
+    @Test
+    void httpsUrlPassthrough() {
+        URI uri = RepositoryUriUtils.toUri("https://repo.example.com/maven";);
+        assertEquals("https", uri.getScheme());
+        assertEquals("repo.example.com", uri.getHost());
+    }
+
+    /**
+     * An opaque {@code file:} URL with an unencoded space (e.g. {@code 
file:repo space}) must not throw
+     * and must resolve to an absolute path that retains the space.
+     * Regression guard for the {@code URI.create()} path that rejects 
unencoded spaces.
+     */
+    @Test
+    void fileUrlOpaqueWithUnencodedSpace() {
+        URI uri = RepositoryUriUtils.toUri("file:repo space");
+        assertEquals("file", uri.getScheme());
+        // path must contain the space, not a percent-encoded form
+        assertTrue(
+                uri.getPath().contains(" ") || 
uri.getSchemeSpecificPart().contains(" "),
+                "Expected a space in the resolved URI but got: " + uri);
+    }
+
+    /**
+     * A hierarchical {@code file:} URL with an unencoded space (e.g. {@code 
file:/repo space}) must not throw
+     * and must resolve to a path that retains the space.
+     * Regression guard for the multi-arg {@code URI} constructor path.
+     */
+    @Test
+    void fileUrlHierarchicalWithUnencodedSpace() {
+        URI uri = RepositoryUriUtils.toUri("file:/repo space");
+        assertEquals("file", uri.getScheme());
+        assertTrue(uri.getPath().contains(" "), "Expected a space in the URI 
path but got: " + uri);
+    }
+
+    /**
+     * A {@code file:} URL with a percent-encoded space (e.g. {@code 
file:repo%20space}) must decode the space
+     * and resolve to an absolute path containing a literal space.
+     */
+    @Test
+    void fileUrlWithPercentEncodedSpace() {
+        URI uri = RepositoryUriUtils.toUri("file:repo%20space");
+        assertEquals("file", uri.getScheme());
+        assertTrue(uri.getPath().contains(" "), "Expected decoded space in the 
URI path but got: " + uri);
+    }
+
+    // ------------------------------------------------------------------
+    // helpers
+    // ------------------------------------------------------------------
+
+    /**
+     * Asserts that {@code path} contains the given drive letter followed by a 
colon or slash,
+     * using a locale-independent comparison.
+     */
+    private static void assertContainsDriveLetter(char driveLetter, String 
path) {
+        char upper = Character.toUpperCase(driveLetter);
+        // Accept both uppercase and lowercase in the URI path; the important 
thing is that
+        // the drive letter (either case) is present and followed by ':' or '/'
+        boolean found = path.indexOf(upper + ":") >= 0
+                || path.indexOf(Character.toLowerCase(upper) + ":") >= 0
+                || path.indexOf("/" + upper + "/") >= 0
+                || path.indexOf("/" + Character.toLowerCase(upper) + "/") >= 0;
+        assertEquals(true, found, "Expected drive letter '" + upper + "' in 
URI path but got: " + path);
+    }
+}

Reply via email to