Commit 92db6315 authored by Mustafa Emre Acer's avatar Mustafa Emre Acer Committed by Commit Bot

Check that strings passed to format_url binary are ASCII hostnames

This binary is used for debugging, so there's no direct impact to Chrome.

Change-Id: Ib6a7120de8e28f135d83e816974e9ccaa3dd077a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913048
Commit-Queue: Mustafa Emre Acer <meacer@chromium.org>
Reviewed-by: default avatarChristopher Thompson <cthomp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734134}
parent 92378355
......@@ -15,6 +15,7 @@
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "components/url_formatter/url_formatter.h"
void PrintUsage(const char* process_name) {
......@@ -22,6 +23,9 @@ void PrintUsage(const char* process_name) {
std::cout << process_name << " <file>" << std::endl;
std::cout << std::endl;
std::cout << "<file> is a text file with one hostname per line." << std::endl;
std::cout << "Hostnames must be in ASCII. Internationalized domain names "
"(IDN) must be encoded in punycode."
<< std::endl;
std::cout << "Each hostname is converted to unicode, if safe. Otherwise, "
<< "it's printed unchanged." << std::endl;
}
......@@ -29,6 +33,14 @@ void PrintUsage(const char* process_name) {
void Convert(std::istream& input) {
base::i18n::InitializeICU();
for (std::string line; std::getline(input, line);) {
CHECK(!base::StartsWith(line,
"http:", base::CompareCase::INSENSITIVE_ASCII) &&
!base::StartsWith(line,
"https:", base::CompareCase::INSENSITIVE_ASCII) &&
base::IsStringASCII(line))
<< "This binary only accepts hostnames in ASCII form (punycode for "
"IDN): "
<< line;
std::cout << line << ", " << url_formatter::IDNToUnicode(line) << std::endl;
}
}
......
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