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

Unified 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: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/content_tests.gypi ('k') | net/base/data_url_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/data_url.cc
diff --git a/net/base/data_url.cc b/net/base/data_url.cc
index e7b46cd44ceb5bc144d29ffc99fb4489a1a02eaf..07fbd1ebc36e7db2f3362ff7e5daf92c90e33512 100644
--- a/net/base/data_url.cc
+++ b/net/base/data_url.cc
@@ -13,6 +13,7 @@
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "net/base/escape.h"
+#include "net/http/http_util.h"
#include "url/gurl.h"
namespace net {
@@ -59,9 +60,18 @@ bool DataURL::Parse(const GURL& url, std::string* mime_type,
}
}
- // fallback to defaults if nothing specified in the URL:
- if (mime_type->empty())
+ if (mime_type->empty()) {
+ // fallback to defaults if nothing specified in the URL:
mime_type->assign("text/plain");
+ } else {
+ // Check grammar.
asanka 2014/03/26 19:42:09 Consider using IsMimeType() instead?
tyoshino (SeeGerritForStatus) 2014/03/26 22:07:00 I considered that. But IsMimeType() doesn't check
asanka 2014/03/26 22:29:42 SGTM
+ std::vector<std::string> mime_type_components;
+ base::SplitString(*mime_type, '/', &mime_type_components);
+ if (mime_type_components.size() != 2 ||
+ !HttpUtil::IsToken(mime_type_components[0]) ||
+ !HttpUtil::IsToken(mime_type_components[1]))
+ return false;
+ }
if (charset->empty())
charset->assign("US-ASCII");
« no previous file with comments | « content/content_tests.gypi ('k') | net/base/data_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698