
It was just using net::UnescapeURLComponent(), which both has some behaviors not suitable for this purpose (Like deliberately leaving some characters we can't safely display to the user, like locks and \x01, escaped). Also, net::GetSuggestedFilename() is specifically designed for this purpose, and has some behaviors that are desireable here (Like replacing characters that shouldn't appear in file names, and trimming whitespace). It turns out that most usages of UnescapeURLComponent() are wrong, and this CL is part of an effort to fix that. Bug: 849998 Change-Id: Ib98e178e7f7cc002e49986026a6799b7c581caa4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1596362 Commit-Queue: Matt Menke <mmenke@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Asanka Herath <asanka@chromium.org> Cr-Commit-Position: refs/heads/master@{#657486}
37 lines
1.3 KiB
C++
37 lines
1.3 KiB
C++
// Copyright 2019 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "pdf/out_of_process_instance.h"
|
|
|
|
#include <string>
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace chrome_pdf {
|
|
|
|
TEST(OutOfProcessInstanceTest, GetFileNameFromUrl) {
|
|
EXPECT_EQ("b.pdf",
|
|
OutOfProcessInstance::GetFileNameFromUrl("https://test/a/b.pdf"));
|
|
|
|
// File extensions should be kept as-is.
|
|
EXPECT_EQ("b.hat",
|
|
OutOfProcessInstance::GetFileNameFromUrl("https://test/a/b.hat"));
|
|
|
|
// Most escaped characters should be unescaped.
|
|
EXPECT_EQ("a b.pdf", OutOfProcessInstance::GetFileNameFromUrl(
|
|
"https://test/%61%20b.pdf"));
|
|
|
|
// Escaped file path delimiters and control codes should be replaced by a
|
|
// placeholder.
|
|
EXPECT_EQ("a_b_.pdf", OutOfProcessInstance::GetFileNameFromUrl(
|
|
"https://test/a%2Fb%01.pdf"));
|
|
|
|
// UTF-8 characters, including ones left escaped by UnescapeURLComponent() for
|
|
// security reasons, are allowed in file paths.
|
|
EXPECT_EQ("\xF0\x9F\x94\x92", OutOfProcessInstance::GetFileNameFromUrl(
|
|
"https://test/%F0%9F%94%92"));
|
|
}
|
|
|
|
} // namespace chrome_pdf
|