HADOOP-16226. new Path(String str) does not remove all the trailing slashes of str
This commit is contained in:
parent
cf268114c9
commit
aaaf856f4b
@ -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 static Path mergePaths(Path path1, Path path2) {
|
||||
* @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.
|
||||
|
@ -121,7 +121,9 @@ public void testNormalize() throws URISyntaxException {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user