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

Side by Side Diff: net/base/data_url_unittest.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.cc ('k') | net/url_request/url_request_data_job_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 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "net/base/data_url.h" 6 #include "net/base/data_url.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 namespace { 10 namespace {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 "text/plain", 56 "text/plain",
57 "US-ASCII", 57 "US-ASCII",
58 "foo" }, 58 "foo" },
59 59
60 { "data:;base64,aGVsbG8gd29ybGQ=", 60 { "data:;base64,aGVsbG8gd29ybGQ=",
61 true, 61 true,
62 "text/plain", 62 "text/plain",
63 "US-ASCII", 63 "US-ASCII",
64 "hello world" }, 64 "hello world" },
65 65
66 // Allow invalid mediatype for backward compatibility but set mime_type to
67 // "text/plain" instead of the invalid mediatype.
68 { "data:foo,boo",
69 true,
70 "text/plain",
71 "US-ASCII",
72 "boo" },
73
74 // When accepting an invalid mediatype, override charset with "US-ASCII"
75 { "data:foo;charset=UTF-8,boo",
76 true,
77 "text/plain",
78 "US-ASCII",
79 "boo" },
80
81 // Invalid mediatype. Includes a slash but the type part is not a token.
82 { "data:f(oo/bar;baz=1;charset=kk,boo",
83 true,
84 "text/plain",
85 "US-ASCII",
86 "boo" },
87
66 { "data:foo/bar;baz=1;charset=kk,boo", 88 { "data:foo/bar;baz=1;charset=kk,boo",
67 true, 89 true,
68 "foo/bar", 90 "foo/bar",
69 "kk", 91 "kk",
70 "boo" }, 92 "boo" },
71 93
72 { "data:foo/bar;charset=kk;baz=1,boo", 94 { "data:foo/bar;charset=kk;baz=1,boo",
73 true, 95 true,
74 "foo/bar", 96 "foo/bar",
75 "kk", 97 "kk",
76 "boo" }, 98 "boo" },
77 99
78 { "data:text/html,%3Chtml%3E%3Cbody%3E%3Cb%3Ehello%20world" 100 { "data:text/html,%3Chtml%3E%3Cbody%3E%3Cb%3Ehello%20world"
79 "%3C%2Fb%3E%3C%2Fbody%3E%3C%2Fhtml%3E", 101 "%3C%2Fb%3E%3C%2Fbody%3E%3C%2Fhtml%3E",
80 true, 102 true,
81 "text/html", 103 "text/html",
82 "US-ASCII", 104 "US-ASCII",
83 "<html><body><b>hello world</b></body></html>" }, 105 "<html><body><b>hello world</b></body></html>" },
84 106
85 { "data:text/html,<html><body><b>hello world</b></body></html>", 107 { "data:text/html,<html><body><b>hello world</b></body></html>",
86 true, 108 true,
87 "text/html", 109 "text/html",
88 "US-ASCII", 110 "US-ASCII",
89 "<html><body><b>hello world</b></body></html>" }, 111 "<html><body><b>hello world</b></body></html>" },
90 112
91 // Bad mime type
92 { "data:f(oo/bar;baz=1;charset=kk,boo",
93 false,
94 "",
95 "",
96 "" },
97
98 // the comma cannot be url-escaped! 113 // the comma cannot be url-escaped!
99 { "data:%2Cblah", 114 { "data:%2Cblah",
100 false, 115 false,
101 "", 116 "",
102 "", 117 "",
103 "" }, 118 "" },
104 119
105 // invalid base64 content 120 // invalid base64 content
106 { "data:;base64,aGVs_-_-", 121 { "data:;base64,aGVs_-_-",
107 false, 122 false,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 bool ok = 194 bool ok =
180 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); 195 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data);
181 EXPECT_EQ(ok, tests[i].is_valid); 196 EXPECT_EQ(ok, tests[i].is_valid);
182 if (tests[i].is_valid) { 197 if (tests[i].is_valid) {
183 EXPECT_EQ(tests[i].mime_type, mime_type); 198 EXPECT_EQ(tests[i].mime_type, mime_type);
184 EXPECT_EQ(tests[i].charset, charset); 199 EXPECT_EQ(tests[i].charset, charset);
185 EXPECT_EQ(tests[i].data, data); 200 EXPECT_EQ(tests[i].data, data);
186 } 201 }
187 } 202 }
188 } 203 }
OLDNEW
« no previous file with comments | « net/base/data_url.cc ('k') | net/url_request/url_request_data_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698