Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: Source/core/loader/LinkHeader.cpp

Issue 1322543003: Fix Link header parsing bug with extension parameter parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use ASCIIType Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/loader/LinkHeader.h ('k') | Source/core/loader/LinkHeaderTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/loader/LinkHeader.h" 6 #include "core/loader/LinkHeader.h"
7 7
8 #include "platform/ParsingUtilities.h" 8 #include "platform/ParsingUtilities.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 // LWSP definition in https://www.ietf.org/rfc/rfc0822.txt 12 // LWSP definition in https://www.ietf.org/rfc/rfc0822.txt
13 template <typename CharType> 13 template <typename CharType>
14 static bool isWhitespace(CharType chr) 14 static bool isWhitespace(CharType chr)
15 { 15 {
16 return (chr == ' ') || (chr == '\t'); 16 return (chr == ' ') || (chr == '\t');
17 } 17 }
18 18
19 template <typename CharType> 19 template <typename CharType>
20 static bool isValidURLChar(CharType chr) 20 static bool isValidURLChar(CharType chr)
21 { 21 {
22 return !isWhitespace(chr) && chr != '>'; 22 return !isWhitespace(chr) && chr != '>';
23 } 23 }
24 24
25 template <typename CharType> 25 template <typename CharType>
26 static bool isValidParameterNameChar(CharType chr) 26 static bool isValidParameterNameChar(CharType chr)
27 { 27 {
28 return !isWhitespace(chr) && chr != '='; 28 // Alpha-numeric is a valid char.
29 // This is likely the common case - bailing early.
30 if (isASCIIAlphanumeric(chr))
31 return true;
32 // A separator or CTL or '%', '*' or '\'' means the char is not valid.
33 if (chr <= ' ' || chr > '|' || chr == '{' || chr == ']' || chr == '['
34 || chr == '/' || chr == '\\' || (chr <= '@' && chr >= ':') || chr == ','
35 || (chr >= '(' && chr <= '*') || chr == '\'' || chr == '"' || chr == '%' ) {
36 return false;
Mike West 2015/09/01 13:48:42 This requires way too much knowledge of ASCII. Lik
37 }
38 return true;
29 } 39 }
30 40
31 template <typename CharType> 41 template <typename CharType>
32 static bool isValidParameterValueEnd(CharType chr) 42 static bool isValidParameterValueEnd(CharType chr)
33 { 43 {
34 return chr == ';' || chr == ','; 44 return chr == ';' || chr == ',';
35 } 45 }
36 46
37 template <typename CharType> 47 template <typename CharType>
38 static bool isValidParameterValueChar(CharType chr) 48 static bool isValidParameterValueChar(CharType chr)
39 { 49 {
40 return !isWhitespace(chr) && !isValidParameterValueEnd(chr); 50 return !isWhitespace(chr) && !isValidParameterValueEnd(chr);
41 } 51 }
42 52
53 // Verify that the parameter is a link-extension which according to spec doesn't have to have a value.
43 static bool isExtensionParameter(LinkHeader::LinkParameterName name) 54 static bool isExtensionParameter(LinkHeader::LinkParameterName name)
44 { 55 {
45 return name > LinkHeader::LinkParameterAnchor; 56 return name > LinkHeader::LinkParameterAnchor;
46 } 57 }
47 58
48 // Before: 59 // Before:
49 // 60 //
50 // <cat.jpg>; rel=preload 61 // <cat.jpg>; rel=preload
51 // ^ ^ 62 // ^ ^
52 // position end 63 // position end
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 template <typename CharType> 296 template <typename CharType>
286 void LinkHeaderSet::init(CharType* headerValue, unsigned len) 297 void LinkHeaderSet::init(CharType* headerValue, unsigned len)
287 { 298 {
288 CharType* position = headerValue; 299 CharType* position = headerValue;
289 CharType* end = headerValue + len; 300 CharType* end = headerValue + len;
290 while (position < end) 301 while (position < end)
291 m_headerSet.append(LinkHeader(position, end)); 302 m_headerSet.append(LinkHeader(position, end));
292 } 303 }
293 304
294 } 305 }
OLDNEW
« no previous file with comments | « Source/core/loader/LinkHeader.h ('k') | Source/core/loader/LinkHeaderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698