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

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

Issue 54233002: Make net::DataURL's MIME string check stricter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split web_url_loader_impl change Created 6 years, 7 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 | Annotate | Revision Log
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
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "net/base/escape.h" 15 #include "net/base/escape.h"
16 #include "net/base/mime_util.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
17 18
18 namespace net { 19 namespace net {
19 20
20 // static 21 // static
21 bool DataURL::Parse(const GURL& url, std::string* mime_type, 22 bool DataURL::Parse(const GURL& url, std::string* mime_type,
22 std::string* charset, std::string* data) { 23 std::string* charset, std::string* data) {
23 DCHECK(mime_type->empty()); 24 DCHECK(mime_type->empty());
24 DCHECK(charset->empty()); 25 DCHECK(charset->empty());
25 std::string::const_iterator begin = url.spec().begin(); 26 std::string::const_iterator begin = url.spec().begin();
(...skipping 26 matching lines...) Expand all
52 bool base64_encoded = false; 53 bool base64_encoded = false;
53 for (; iter != meta_data.end(); ++iter) { 54 for (; iter != meta_data.end(); ++iter) {
54 if (!base64_encoded && *iter == kBase64Tag) { 55 if (!base64_encoded && *iter == kBase64Tag) {
55 base64_encoded = true; 56 base64_encoded = true;
56 } else if (charset->empty() && 57 } else if (charset->empty() &&
57 iter->compare(0, kCharsetTagLength, kCharsetTag) == 0) { 58 iter->compare(0, kCharsetTagLength, kCharsetTag) == 0) {
58 charset->assign(iter->substr(kCharsetTagLength)); 59 charset->assign(iter->substr(kCharsetTagLength));
59 } 60 }
60 } 61 }
61 62
62 // fallback to defaults if nothing specified in the URL: 63 if (mime_type->empty()) {
63 if (mime_type->empty()) 64 // fallback to defaults if nothing specified in the URL:
64 mime_type->assign("text/plain"); 65 mime_type->assign("text/plain");
66 } else if (!ParseMimeTypeWithoutParameter(*mime_type, NULL, NULL)) {
67 return false;
68 }
65 if (charset->empty()) 69 if (charset->empty())
66 charset->assign("US-ASCII"); 70 charset->assign("US-ASCII");
67 71
68 // The caller may not be interested in receiving the data. 72 // The caller may not be interested in receiving the data.
69 if (!data) 73 if (!data)
70 return true; 74 return true;
71 75
72 // Preserve spaces if dealing with text or xml input, same as mozilla: 76 // Preserve spaces if dealing with text or xml input, same as mozilla:
73 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052 77 // https://bugzilla.mozilla.org/show_bug.cgi?id=138052
74 // but strip them otherwise: 78 // but strip them otherwise:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 temp_data.resize(length + padding_needed, '='); 118 temp_data.resize(length + padding_needed, '=');
115 } 119 }
116 return base::Base64Decode(temp_data, data); 120 return base::Base64Decode(temp_data, data);
117 } 121 }
118 122
119 temp_data.swap(*data); 123 temp_data.swap(*data);
120 return true; 124 return true;
121 } 125 }
122 126
123 } // namespace net 127 } // namespace net
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc ('k') | net/base/data_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698