Commit 627af5f0 authored by Ian Clelland's avatar Ian Clelland Committed by Commit Bot

Allow "*" as the leading character in structured header tokens.

This affects the parsing and serialization of tokens in structured
headers draft 15 and above. When operating in Draft 9 mode for backwards
compatibility, a character sequence beginning with an asterisk will be
parsed as a byte sequence instead.

Bug: 1048756
Change-Id: I5b1e2a57501a2e2dedb1183f495f71d75146c46b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2084711Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746380}
parent 2592bd4a
...@@ -305,7 +305,8 @@ class StructuredHeaderParser { ...@@ -305,7 +305,8 @@ class StructuredHeaderParser {
// Parses a Token ([SH09] 4.2.10, [SH15] 4.2.6). // Parses a Token ([SH09] 4.2.10, [SH15] 4.2.6).
base::Optional<Item> ReadToken() { base::Optional<Item> ReadToken() {
if (input_.empty() || !base::IsAsciiAlpha(input_.front())) { if (input_.empty() ||
!(base::IsAsciiAlpha(input_.front()) || input_.front() == '*')) {
LogParseError("ReadToken", "ALPHA"); LogParseError("ReadToken", "ALPHA");
return base::nullopt; return base::nullopt;
} }
...@@ -538,7 +539,8 @@ class StructuredHeaderSerializer { ...@@ -538,7 +539,8 @@ class StructuredHeaderSerializer {
if (value.is_token()) { if (value.is_token()) {
// Serializes a Token ([SH15] 4.1.7). // Serializes a Token ([SH15] 4.1.7).
if (!value.GetString().size() || if (!value.GetString().size() ||
!base::IsAsciiAlpha(value.GetString().front())) !(base::IsAsciiAlpha(value.GetString().front()) ||
value.GetString().front() == '*'))
return false; return false;
if (value.GetString().find_first_not_of(kTokenChars15) != if (value.GetString().find_first_not_of(kTokenChars15) !=
std::string::npos) std::string::npos)
......
...@@ -61,6 +61,7 @@ const struct ItemTestCase { ...@@ -61,6 +61,7 @@ const struct ItemTestCase {
{"bad token - item", "abc$@%!", base::nullopt}, {"bad token - item", "abc$@%!", base::nullopt},
{"leading whitespace", " foo", Token("foo"), "foo"}, {"leading whitespace", " foo", Token("foo"), "foo"},
{"trailing whitespace", "foo ", Token("foo"), "foo"}, {"trailing whitespace", "foo ", Token("foo"), "foo"},
{"leading asterisk", "*foo", Token("*foo")},
// Number // Number
{"basic integer", "42", Integer(42L)}, {"basic integer", "42", Integer(42L)},
{"zero integer", "0", Integer(0L)}, {"zero integer", "0", Integer(0L)},
...@@ -427,6 +428,7 @@ const ItemTestCase sh09_item_test_cases[] = { ...@@ -427,6 +428,7 @@ const ItemTestCase sh09_item_test_cases[] = {
"*iQ==*"}, "*iQ==*"},
{"non-ASCII binary", "*/+Ah*", Item("\xFF\xE0!", Item::kByteSequenceType)}, {"non-ASCII binary", "*/+Ah*", Item("\xFF\xE0!", Item::kByteSequenceType)},
{"base64url binary", "*_-Ah*", base::nullopt}, {"base64url binary", "*_-Ah*", base::nullopt},
{"token with leading asterisk", "*foo", base::nullopt},
}; };
// For Structured Headers Draft 15 // For Structured Headers Draft 15
...@@ -763,7 +765,6 @@ TEST(StructuredHeaderTest, UnserializableTokens) { ...@@ -763,7 +765,6 @@ TEST(StructuredHeaderTest, UnserializableTokens) {
{"begins with colon", ":token"}, {"begins with colon", ":token"},
{"begins with percent", "%token"}, {"begins with percent", "%token"},
{"begins with period", ".token"}, {"begins with period", ".token"},
{"begins with asterisk", "*token"},
{"begins with slash", "/token"}, {"begins with slash", "/token"},
}; };
for (const auto& bad_token : bad_tokens) { for (const auto& bad_token : bad_tokens) {
......
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