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

bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git

commit 4dec3b0f783fcd4a775d0252ec5229bda1d9b50d
Author: Stefan Bodewig <[email protected]>
AuthorDate: Sun Jun 8 09:51:58 2025 +0200

    only strip leading character in getName when it actually is a path separator
    
    https://bz.apache.org/bugzilla/show_bug.cgi?id=69680
---
 .../tools/ant/types/resources/URLResource.java     |  4 +--
 .../tools/ant/types/resources/URLResourceTest.java | 36 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/main/org/apache/tools/ant/types/resources/URLResource.java 
b/src/main/org/apache/tools/ant/types/resources/URLResource.java
index 1772b4532..479d53f9c 100644
--- a/src/main/org/apache/tools/ant/types/resources/URLResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/URLResource.java
@@ -183,7 +183,7 @@ public class URLResource extends Resource implements 
URLProvider {
             return getRef().getName();
         }
         String name = getURL().getFile();
-        return name.isEmpty() ? name : name.substring(1);
+        return FILE_UTILS.stripLeadingPathSeparator(name);
     }
 
     /**
@@ -196,7 +196,7 @@ public class URLResource extends Resource implements 
URLProvider {
     }
 
     /**
-     * Find out whether the URL exists .
+     * Find out whether the URL exists.
      * @return true if this resource exists.
      */
     public synchronized boolean isExists() {
diff --git 
a/src/tests/junit/org/apache/tools/ant/types/resources/URLResourceTest.java 
b/src/tests/junit/org/apache/tools/ant/types/resources/URLResourceTest.java
new file mode 100644
index 000000000..84bf23dc2
--- /dev/null
+++ b/src/tests/junit/org/apache/tools/ant/types/resources/URLResourceTest.java
@@ -0,0 +1,36 @@
+/*
+ *  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
+ *
+ *      https://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.apache.tools.ant.types.resources;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class URLResourceTest {
+
+    /**
+     * @see "https://bz.apache.org/bugzilla/show_bug.cgi?id=69680";
+     */
+    @Test
+    public void getNameOnlyStripsLeadingPathSeparator() {
+        assertEquals("foo", new URLResource("file:/foo").getName());
+        assertEquals("foo", new URLResource("file://host/foo").getName());
+        assertEquals("file:/foo!/bar", new 
URLResource("jar:file:/foo!/bar").getName());
+    }
+}

Reply via email to