You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by aa...@apache.org on 2019/04/03 04:18:45 UTC

[hadoop] branch branch-3.2 updated: HADOOP-16226. new Path(String str) does not remove all the trailing slashes of str

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

aajisaka pushed a commit to branch branch-3.2
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-3.2 by this push:
     new b6039e2  HADOOP-16226. new Path(String str) does not remove all the trailing slashes of str
b6039e2 is described below

commit b6039e241d19b043d5b4de9cbc3b9be4bb534dca
Author: Akira Ajisaka <aa...@apache.org>
AuthorDate: Tue Apr 2 09:16:32 2019 +0900

    HADOOP-16226. new Path(String str) does not remove all the trailing slashes of str
    
    (cherry picked from commit aaaf856f4b7b53d424eb1eab010311de0d5fbe1e)
---
 .../hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java     | 7 +++++--
 .../hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java | 2 ++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java
index b48a351..c5ba3a2 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java
@@ -70,6 +70,9 @@ public class Path
   private static final Pattern HAS_DRIVE_LETTER_SPECIFIER =
       Pattern.compile("^/?[a-zA-Z]:");
 
+  /** Pre-compiled regular expressions to detect duplicated slashes. */
+  private static final Pattern SLASHES = Pattern.compile("/+");
+
   private static final long serialVersionUID = 0xad00f;
 
   private URI uri; // a hierarchical uri
@@ -291,8 +294,8 @@ public class Path
    * @return the normalized path string
    */
   private static String normalizePath(String scheme, String path) {
-    // Remove double forward slashes.
-    path = StringUtils.replace(path, "//", "/");
+    // Remove duplicated slashes.
+    path = SLASHES.matcher(path).replaceAll("/");
 
     // Remove backslashes if this looks like a Windows path. Avoid
     // the substitution if it looks like a non-local URI.
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java
index 5123526..c0d79c1 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestPath.java
@@ -121,7 +121,9 @@ public class TestPath {
     assertEquals("/foo", new Path("/foo/").toString());
     assertEquals("foo", new Path("foo/").toString());
     assertEquals("foo", new Path("foo//").toString());
+    assertEquals("foo", new Path("foo///").toString());
     assertEquals("foo/bar", new Path("foo//bar").toString());
+    assertEquals("foo/bar", new Path("foo///bar").toString());
     assertEquals("hdfs://foo/foo2/bar/baz/",
         new Path(new URI("hdfs://foo//foo2///bar/baz///")).toString());
     if (Path.WINDOWS) {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org