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

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: Changed valid char to match the spec 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 ((chr >= 'a' && chr <= 'z') || (chr >= 'A' && chr <= 'Z') || (chr >= '0' && chr <= '9'))
Nate Chapin 2015/08/27 23:11:48 Can we simplify some of this function by reusing h
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 == '%' )
Nate Chapin 2015/08/27 23:11:48 Nit: add {}
36 return false;
37 return true;
29 } 38 }
30 39
31 template <typename CharType> 40 template <typename CharType>
32 static bool isValidParameterValueEnd(CharType chr) 41 static bool isValidParameterValueEnd(CharType chr)
33 { 42 {
34 return chr == ';' || chr == ','; 43 return chr == ';' || chr == ',';
35 } 44 }
36 45
37 template <typename CharType> 46 template <typename CharType>
38 static bool isValidParameterValueChar(CharType chr) 47 static bool isValidParameterValueChar(CharType chr)
39 { 48 {
40 return !isWhitespace(chr) && !isValidParameterValueEnd(chr); 49 return !isWhitespace(chr) && !isValidParameterValueEnd(chr);
41 } 50 }
42 51
52 // 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) 53 static bool isExtensionParameter(LinkHeader::LinkParameterName name)
44 { 54 {
45 return name > LinkHeader::LinkParameterAnchor; 55 return name > LinkHeader::LinkParameterAnchor;
46 } 56 }
47 57
48 // Before: 58 // Before:
49 // 59 //
50 // <cat.jpg>; rel=preload 60 // <cat.jpg>; rel=preload
51 // ^ ^ 61 // ^ ^
52 // position end 62 // position end
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 template <typename CharType> 295 template <typename CharType>
286 void LinkHeaderSet::init(CharType* headerValue, unsigned len) 296 void LinkHeaderSet::init(CharType* headerValue, unsigned len)
287 { 297 {
288 CharType* position = headerValue; 298 CharType* position = headerValue;
289 CharType* end = headerValue + len; 299 CharType* end = headerValue + len;
290 while (position < end) 300 while (position < end)
291 m_headerSet.append(LinkHeader(position, end)); 301 m_headerSet.append(LinkHeader(position, end));
292 } 302 }
293 303
294 } 304 }
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