Chromium Code Reviews| Index: Source/core/platform/network/ParsedContentType.cpp |
| diff --git a/Source/core/platform/network/ParsedContentType.cpp b/Source/core/platform/network/ParsedContentType.cpp |
| index d8db86a8f3b8e6df430639c5b1ab9db6e42a696e..309676c5c07d9ec89812cc24f1d55626e35b5bf9 100644 |
| --- a/Source/core/platform/network/ParsedContentType.cpp |
| +++ b/Source/core/platform/network/ParsedContentType.cpp |
| @@ -49,12 +49,7 @@ static void skipSpaces(const String& input, unsigned& startIndex) |
| ++startIndex; |
| } |
| -static bool isTokenCharacter(char c) |
| -{ |
| - return isASCII(c) && c > ' ' && c != '"' && c != '(' && c != ')' && c != ',' && c != '/' && (c < ':' || c > '@') && (c < '[' || c > ']'); |
| -} |
| - |
| -static SubstringRange parseToken(const String& input, unsigned& startIndex) |
| +static SubstringRange parseParameterPart(const String& input, unsigned& startIndex) |
| { |
| unsigned inputLength = input.length(); |
| unsigned tokenStart = startIndex; |
| @@ -63,42 +58,21 @@ static SubstringRange parseToken(const String& input, unsigned& startIndex) |
| if (tokenEnd >= inputLength) |
| return SubstringRange(); |
| + bool quoted = input[tokenStart] == '\"'; |
| + bool escape = false; |
| + |
| while (tokenEnd < inputLength) { |
|
abarth-chromium
2013/09/16 19:41:42
Rather than calling input[tokenEnd] multiple times
|
| - if (!isTokenCharacter(input[tokenEnd])) |
| + if (quoted && tokenStart != tokenEnd && input[tokenEnd] == '\"' && !escape) |
| + return SubstringRange(tokenStart + 1, tokenEnd++ - tokenStart - 1); |
| + if (!quoted && (input[tokenEnd] == ';' || input[tokenEnd] == '=')) |
| return SubstringRange(tokenStart, tokenEnd - tokenStart); |
| + escape = !escape && input[tokenEnd] == '\\'; |
| ++tokenEnd; |
| } |
| return SubstringRange(tokenStart, tokenEnd - tokenStart); |
| } |
| -static SubstringRange parseQuotedString(const String& input, unsigned& startIndex) |
| -{ |
| - unsigned inputLength = input.length(); |
| - unsigned quotedStringStart = startIndex + 1; |
| - unsigned& quotedStringEnd = startIndex; |
| - |
| - if (quotedStringEnd >= inputLength) |
| - return SubstringRange(); |
| - |
| - if (input[quotedStringEnd++] != '"' || quotedStringEnd >= inputLength) |
| - return SubstringRange(); |
| - |
| - bool lastCharacterWasBackslash = false; |
| - char currentCharacter; |
| - while ((currentCharacter = input[quotedStringEnd++]) != '"' || lastCharacterWasBackslash) { |
| - if (quotedStringEnd >= inputLength) |
| - return SubstringRange(); |
| - if (currentCharacter == '\\' && !lastCharacterWasBackslash) { |
| - lastCharacterWasBackslash = true; |
| - continue; |
| - } |
| - if (lastCharacterWasBackslash) |
| - lastCharacterWasBackslash = false; |
| - } |
| - return SubstringRange(quotedStringStart, quotedStringEnd - quotedStringStart - 1); |
| -} |
| - |
| static String substringForRange(const String& string, const SubstringRange& range) |
| { |
| return string.substring(range.first, range.second); |
| @@ -172,34 +146,29 @@ bool parseContentType(const String& contentType, ReceiverType& receiver) |
| index = semiColonIndex + 1; |
| while (true) { |
| skipSpaces(contentType, index); |
| - SubstringRange keyRange = parseToken(contentType, index); |
| + SubstringRange keyRange = parseParameterPart(contentType, index); |
| if (!keyRange.second || index >= contentTypeLength) { |
| - LOG_ERROR("Invalid Content-Type parameter name."); |
| + LOG_ERROR("Invalid Content-Type parameter name. (at %i)", index); |
| return false; |
| } |
| // Should we tolerate spaces here? |
| if (contentType[index++] != '=' || index >= contentTypeLength) { |
| - LOG_ERROR("Invalid Content-Type malformed parameter."); |
| + LOG_ERROR("Invalid Content-Type malformed parameter (at %i).", index); |
| return false; |
| } |
| // Should we tolerate spaces here? |
| - String value; |
| - SubstringRange valueRange; |
| - if (contentType[index] == '"') |
| - valueRange = parseQuotedString(contentType, index); |
| - else |
| - valueRange = parseToken(contentType, index); |
| + SubstringRange valueRange = parseParameterPart(contentType, index); |
| if (!valueRange.second) { |
| - LOG_ERROR("Invalid Content-Type, invalid parameter value."); |
| + LOG_ERROR("Invalid Content-Type, invalid parameter value (at %i, for '%s').", index, substringForRange(contentType, keyRange).stripWhiteSpace().ascii().data()); |
| return false; |
| } |
| // Should we tolerate spaces here? |
| if (index < contentTypeLength && contentType[index++] != ';') { |
| - LOG_ERROR("Invalid Content-Type, invalid character at the end of key/value parameter."); |
| + LOG_ERROR("Invalid Content-Type, invalid character at the end of key/value parameter (at %i).", index); |
| return false; |
| } |