Commit 8972d1c0 authored by Dave Schuyler's avatar Dave Schuyler Committed by Commit Bot

[net/base] typos in comments and style changes

This CL addresses some comment typos and style changes. These changes
were included with 1066732, which was reverted. Separating these changes
in this CL will make further CLs on these files cleaner (fewer lines
changing).

There are no logic changes in this CL.

Bug: None
Change-Id: Ic2d75bdf2f1726d9044da18caec56ec5b374100f
Reviewed-on: https://chromium-review.googlesource.com/1071093
Commit-Queue: Dave Schuyler <dschuyler@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561370}
parent 2c33a879
......@@ -83,8 +83,9 @@ std::string Escape(base::StringPiece text,
// allowed in query strings according to http://www.ietf.org/rfc/rfc3261.txt are
// not unescaped, to avoid turning a valid url according to spec into an
// invalid one.
// clang-format off
const char kUrlUnescape[128] = {
// NULL, control chars...
// Null, control chars...
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// ' ' ! " # $ % & ' ( ) * + , - . /
......@@ -98,8 +99,9 @@ const char kUrlUnescape[128] = {
// ` a b c d e f g h i j k l m n o
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
// p q r s t u v w x y z { | } ~ <NBSP>
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0,
};
// clang-format on
// Attempts to unescape the sequence at |index| within |escaped_text|. If
// successful, sets |value| to the unescaped value. Returns whether
......@@ -183,16 +185,16 @@ bool ShouldUnescapeCodePoint(UnescapeRule::Type rules, uint32_t code_point) {
(rules & UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS));
}
// Compare the codepoint against a list of characters that can be used
// Compare the code point against a list of characters that can be used
// to spoof other URLs.
//
// Can't use icu to make this cleaner, because Cronet cannot depend on
// icu, and currently uses this file.
// TODO(https://crbug.com/829873): Try to make this use icu, both to
// protect against regressions as the Unicode stndard is updated and to
// protect against regressions as the Unicode standard is updated and to
// reduce the number of long lists of characters.
// TODO(https://crbug.com/824715): Add default ignoreable and formatting
// codepoints.
// TODO(https://crbug.com/824715): Add default ignorable and formatting
// code points.
return !(
// Per http://tools.ietf.org/html/rfc3987#section-4.1, certain BiDi
// control characters are not allowed to appear unescaped in URLs.
......@@ -243,7 +245,7 @@ bool ShouldUnescapeCodePoint(UnescapeRule::Type rules, uint32_t code_point) {
}
// Unescapes |escaped_text| according to |rules|, returning the resulting
// string. Fills in an |adjustments| parameter, if non-NULL, so it reflects
// string. Fills in an |adjustments| parameter, if non-nullptr, so it reflects
// the alterations done to the string that are not one-character-to-one-
// character. The resulting |adjustments| will always be sorted by increasing
// offset.
......@@ -322,17 +324,15 @@ std::string UnescapeURLWithAdjustmentsImpl(
return result;
}
// Convert a character |c| to a form that will not be mistaken as HTML.
template <class str>
void AppendEscapedCharForHTMLImpl(typename str::value_type c, str* output) {
static constexpr struct {
char key;
base::StringPiece replacement;
} kCharsToEscape[] = {
{ '<', "&lt;" },
{ '>', "&gt;" },
{ '&', "&amp;" },
{ '"', "&quot;" },
{ '\'', "&#39;" },
{'<', "&lt;"}, {'>', "&gt;"}, {'&', "&amp;"},
{'"', "&quot;"}, {'\'', "&#39;"},
};
for (const auto& char_to_escape : kCharsToEscape) {
if (c == char_to_escape.key) {
......@@ -344,6 +344,7 @@ void AppendEscapedCharForHTMLImpl(typename str::value_type c, str* output) {
output->push_back(c);
}
// Convert |input| string to a form that will not be interpreted as HTML.
template <class str>
str EscapeForHTMLImpl(base::BasicStringPiece<str> input) {
str result;
......@@ -438,12 +439,12 @@ base::string16 EscapeForHTML(base::StringPiece16 input) {
std::string UnescapeURLComponent(base::StringPiece escaped_text,
UnescapeRule::Type rules) {
return UnescapeURLWithAdjustmentsImpl(escaped_text, rules, NULL);
return UnescapeURLWithAdjustmentsImpl(escaped_text, rules, nullptr);
}
base::string16 UnescapeAndDecodeUTF8URLComponent(base::StringPiece text,
UnescapeRule::Type rules) {
return UnescapeAndDecodeUTF8URLComponentWithAdjustments(text, rules, NULL);
return UnescapeAndDecodeUTF8URLComponentWithAdjustments(text, rules, nullptr);
}
base::string16 UnescapeAndDecodeUTF8URLComponentWithAdjustments(
......@@ -510,17 +511,15 @@ base::string16 UnescapeForHTML(base::StringPiece16 input) {
const char* ampersand_code;
const char replacement;
} kEscapeToChars[] = {
{ "&lt;", '<' },
{ "&gt;", '>' },
{ "&amp;", '&' },
{ "&quot;", '"' },
{ "&#39;", '\''},
{"&lt;", '<'}, {"&gt;", '>'}, {"&amp;", '&'},
{"&quot;", '"'}, {"&#39;", '\''},
};
constexpr size_t kEscapeToCharsCount = base::size(kEscapeToChars);
if (input.find(base::ASCIIToUTF16("&")) == std::string::npos)
return input.as_string();
base::string16 ampersand_chars[base::size(kEscapeToChars)];
base::string16 ampersand_chars[kEscapeToCharsCount];
base::string16 text = input.as_string();
for (base::string16::iterator iter = text.begin();
iter != text.end(); ++iter) {
......
......@@ -48,14 +48,14 @@ NET_EXPORT std::string EscapeNonASCII(base::StringPiece input);
// Escapes characters in text suitable for use as an external protocol handler
// command.
// We %XX everything except alphanumerics and -_.!~*'() and the restricted
// chracters (;/?:@&=+$,#[]) and a valid percent escape sequence (%XX).
// characters (;/?:@&=+$,#[]) and a valid percent escape sequence (%XX).
NET_EXPORT std::string EscapeExternalHandlerValue(base::StringPiece text);
// Appends the given character to the output string, escaping the character if
// the character would be interpretted as an HTML delimiter.
// the character would be interpreted as an HTML delimiter.
NET_EXPORT void AppendEscapedCharForHTML(char c, std::string* output);
// Escapes chars that might cause this text to be interpretted as HTML tags.
// Escapes chars that might cause this text to be interpreted as HTML tags.
NET_EXPORT std::string EscapeForHTML(base::StringPiece text);
NET_EXPORT base::string16 EscapeForHTML(base::StringPiece16 text);
......@@ -120,7 +120,7 @@ NET_EXPORT std::string UnescapeURLComponent(base::StringPiece escaped_text,
UnescapeRule::Type rules);
// Unescapes the given substring as a URL, and then tries to interpret the
// result as being encoded as UTF-8. If the result is convertable into UTF-8, it
// result as being encoded as UTF-8. If the result is convertible into UTF-8, it
// will be returned as converted. If it is not, the original escaped string will
// be converted into a base::string16 and returned. |adjustments| provides
// information on how the original string was adjusted to get the string
......
......@@ -430,9 +430,9 @@ TEST(EscapeTest, UnescapeBinaryURLComponent) {
TEST(EscapeTest, EscapeForHTML) {
const EscapeForHTMLCase tests[] = {
{ "hello", "hello" },
{ "<hello>", "&lt;hello&gt;" },
{ "don\'t mess with me", "don&#39;t mess with me" },
{"hello", "hello"},
{"<hello>", "&lt;hello&gt;"},
{"don\'t mess with me", "don&#39;t mess with me"},
};
for (const auto& test : tests) {
std::string result = EscapeForHTML(std::string(test.input));
......@@ -442,17 +442,17 @@ TEST(EscapeTest, EscapeForHTML) {
TEST(EscapeTest, UnescapeForHTML) {
const EscapeForHTMLCase tests[] = {
{ "", "" },
{ "&lt;hello&gt;", "<hello>" },
{ "don&#39;t mess with me", "don\'t mess with me" },
{ "&lt;&gt;&amp;&quot;&#39;", "<>&\"'" },
{ "& lt; &amp ; &; '", "& lt; &amp ; &; '" },
{ "&amp;", "&" },
{ "&quot;", "\"" },
{ "&#39;", "'" },
{ "&lt;", "<" },
{ "&gt;", ">" },
{ "&amp; &", "& &" },
{"", ""},
{"&lt;hello&gt;", "<hello>"},
{"don&#39;t mess with me", "don\'t mess with me"},
{"&lt;&gt;&amp;&quot;&#39;", "<>&\"'"},
{"& lt; &amp ; &; '", "& lt; &amp ; &; '"},
{"&amp;", "&"},
{"&quot;", "\""},
{"&#39;", "'"},
{"&lt;", "<"},
{"&gt;", ">"},
{"&amp; &", "& &"},
};
for (const auto& test : tests) {
base::string16 result = UnescapeForHTML(base::ASCIIToUTF16(test.input));
......
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