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

Side by Side Diff: net/base/data_url.cc

Issue 674823002: [Regression fix] [Data URI parser] Accept data URI with invalid mediatype data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2171
Patch Set: Created 6 years, 2 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 | « net/base/data_url.h ('k') | net/base/data_url_unittest.cc » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // NOTE: based loosely on mozilla's nsDataChannel.cpp 5 // NOTE: based loosely on mozilla's nsDataChannel.cpp
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "net/base/data_url.h" 9 #include "net/base/data_url.h"
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 iter->compare(0, kCharsetTagLength, kCharsetTag) == 0) { 59 iter->compare(0, kCharsetTagLength, kCharsetTag) == 0) {
60 charset->assign(iter->substr(kCharsetTagLength)); 60 charset->assign(iter->substr(kCharsetTagLength));
61 // The grammar for charset is not specially defined in RFC2045 and 61 // The grammar for charset is not specially defined in RFC2045 and
62 // RFC2397. It just needs to be a token. 62 // RFC2397. It just needs to be a token.
63 if (!net::HttpUtil::IsToken(*charset)) 63 if (!net::HttpUtil::IsToken(*charset))
64 return false; 64 return false;
65 } 65 }
66 } 66 }
67 67
68 if (mime_type->empty()) { 68 if (mime_type->empty()) {
69 // fallback to defaults if nothing specified in the URL: 69 // Fallback to the default if nothing specified in the mediatype part as
70 // specified in RFC2045. As specified in RFC2397, we use |charset| even if
71 // |mime_type| is empty.
70 mime_type->assign("text/plain"); 72 mime_type->assign("text/plain");
71 } else if (!ParseMimeTypeWithoutParameter(*mime_type, NULL, NULL)) { 73 } else if (!ParseMimeTypeWithoutParameter(*mime_type, NULL, NULL)) {
72 return false; 74 // Fallback to the default as recommended in RFC2045 when the mediatype
75 // value is invalid. For this case, we don't respect |charset| but force it
76 // set to "US-ASCII".
77 mime_type->assign("text/plain");
78 charset->assign("US-ASCII");
73 } 79 }
74 if (charset->empty()) 80 if (charset->empty())
75 charset->assign("US-ASCII"); 81 charset->assign("US-ASCII");
76 82
77 // The caller may not be interested in receiving the data. 83 // The caller may not be interested in receiving the data.
78 if (!data) 84 if (!data)
79 return true; 85 return true;
80 86
81 // Preserve spaces if dealing with text or xml input, same as mozilla: 87 // Preserve spaces if dealing with text or xml input, same as mozilla:
82 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052 88 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 temp_data.resize(length + padding_needed, '='); 129 temp_data.resize(length + padding_needed, '=');
124 } 130 }
125 return base::Base64Decode(temp_data, data); 131 return base::Base64Decode(temp_data, data);
126 } 132 }
127 133
128 temp_data.swap(*data); 134 temp_data.swap(*data);
129 return true; 135 return true;
130 } 136 }
131 137
132 } // namespace net 138 } // namespace net
OLDNEW
« no previous file with comments | « net/base/data_url.h ('k') | net/base/data_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698