Commit 31233e09 authored by Ryo Hashimoto's avatar Ryo Hashimoto Committed by Commit Bot

arc: Unescape file name for ArcFileSystemHost::GetFileName

GURL::ExtractFileName() does not unescape the string.

Bug: 806192
Test: unit_tests --gtest_filter="ArcFileSystemBridgeTest.*"
Change-Id: I31409e7554ae361de9cca809dfbe1a6ef6111b0e
Reviewed-on: https://chromium-review.googlesource.com/888189Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Ryo Hashimoto <hashimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532314}
parent a04b788b
......@@ -23,6 +23,7 @@
#include "extensions/browser/api/file_handlers/mime_util.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
#include "net/base/escape.h"
#include "storage/browser/fileapi/file_system_context.h"
namespace arc {
......@@ -152,7 +153,10 @@ void ArcFileSystemBridge::GetFileName(const std::string& url,
std::move(callback).Run(base::nullopt);
return;
}
std::move(callback).Run(url_decoded.ExtractFileName());
std::move(callback).Run(net::UnescapeURLComponent(
url_decoded.ExtractFileName(),
net::UnescapeRule::SPACES |
net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS));
}
void ArcFileSystemBridge::GetFileSize(const std::string& url,
......
......@@ -11,6 +11,7 @@
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/arc/fileapi/chrome_content_provider_url_util.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
......@@ -118,17 +119,38 @@ TEST_F(ArcFileSystemBridgeTest, GetFileName) {
base::RunLoop run_loop;
arc_file_system_bridge_->GetFileName(
EncodeToChromeContentProviderUrl(GURL(kTestUrl)).spec(),
base::Bind(
base::BindOnce(
[](base::RunLoop* run_loop,
const base::Optional<std::string>& result) {
run_loop->Quit();
ASSERT_TRUE(result.has_value());
EXPECT_EQ("File 1.txt", result.value());
run_loop->Quit();
},
&run_loop));
run_loop.Run();
}
TEST_F(ArcFileSystemBridgeTest, GetFileNameNonASCII) {
const std::string filename = base::UTF16ToUTF8(base::string16({
0x307b, // HIRAGANA_LETTER_HO
0x3052, // HIRAGANA_LETTER_GE
}));
const GURL url("externalfile:drive-test-user-hash/root/" + filename);
base::RunLoop run_loop;
arc_file_system_bridge_->GetFileName(
EncodeToChromeContentProviderUrl(url).spec(),
base::BindOnce(
[](base::RunLoop* run_loop, const std::string& expected,
const base::Optional<std::string>& result) {
run_loop->Quit();
ASSERT_TRUE(result.has_value());
EXPECT_EQ(expected, result.value());
},
&run_loop, filename));
run_loop.Run();
}
TEST_F(ArcFileSystemBridgeTest, GetFileSize) {
base::RunLoop run_loop;
arc_file_system_bridge_->GetFileSize(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment