From f92a4904bf4822eb6e73e6d225dd2d40c7975315 Mon Sep 17 00:00:00 2001 From: Haohui Mai Date: Tue, 17 Feb 2015 13:04:38 -0800 Subject: [PATCH] HDFS-6662. WebHDFS cannot open a file if its path contains "%". Contributed by Gerson Carlos. --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../datanode/web/webhdfs/ParameterParser.java | 2 +- .../hadoop-hdfs/src/main/webapps/hdfs/explorer.js | 7 +++++++ .../datanode/web/webhdfs/TestParameterParser.java | 13 +++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 9bd4fa8fdaf..a13014ae3b3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -673,6 +673,9 @@ Release 2.7.0 - UNRELEASED HDFS-7798. Checkpointing failure caused by shared KerberosAuthenticator. (Chengbing Liu via yliu) + HDFS-6662. WebHDFS cannot open a file if its path contains "%". + (Gerson Carlos via wheat9) + BREAKDOWN OF HDFS-7584 SUBTASKS AND RELATED JIRAS HDFS-7720. Quota by Storage Type API, tools and ClientNameNode diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/web/webhdfs/ParameterParser.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/web/webhdfs/ParameterParser.java index e1930b057c4..57495046899 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/web/webhdfs/ParameterParser.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/web/webhdfs/ParameterParser.java @@ -50,7 +50,7 @@ class ParameterParser { private final Map> params; ParameterParser(QueryStringDecoder decoder, Configuration conf) { - this.path = decoder.path().substring(WEBHDFS_PREFIX_LENGTH); + this.path = QueryStringDecoder.decodeComponent(decoder.path().substring(WEBHDFS_PREFIX_LENGTH)); this.params = decoder.parameters(); this.conf = conf; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js index ca73506a619..87d47fad9e6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/hdfs/explorer.js @@ -102,6 +102,13 @@ menus.change(); } + function encode_path(abs_path) { + abs_path = encodeURIComponent(abs_path); + var re = /%2F/g; + return abs_path.replace(re, '/'); + } + + abs_path = encode_path(abs_path); var url = '/webhdfs/v1' + abs_path + '?op=GET_BLOCK_LOCATIONS'; $.get(url).done(function(data) { var d = get_response(data, "LocatedBlocks"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/web/webhdfs/TestParameterParser.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/web/webhdfs/TestParameterParser.java index 8b4235b8862..6a6c5d05d9b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/web/webhdfs/TestParameterParser.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/web/webhdfs/TestParameterParser.java @@ -52,4 +52,17 @@ public class TestParameterParser { final Token tok2 = testParser.delegationToken(); Assert.assertTrue(HAUtil.isTokenForLogicalUri(tok2)); } + + @Test + public void testDecodePath() { + final String SCAPED_PATH = "hdfs-6662/test%25251%26%3Dtest?op=OPEN"; + final String EXPECTED_PATH = "/hdfs-6662/test%251&=test"; + + Configuration conf = DFSTestUtil.newHAConfiguration(LOGICAL_NAME); + QueryStringDecoder decoder = new QueryStringDecoder( + WebHdfsHandler.WEBHDFS_PREFIX + "/" + + SCAPED_PATH); + ParameterParser testParser = new ParameterParser(decoder, conf); + Assert.assertEquals(EXPECTED_PATH, testParser.path()); + } }