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

Unified Diff: third_party/WebKit/Source/core/fileapi/Blob.cpp

Issue 1362963003: Blob/File constructors/slice method shouldn't throw on invalid types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated win expectation Created 3 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 | « third_party/WebKit/Source/core/fileapi/Blob.h ('k') | third_party/WebKit/Source/core/fileapi/File.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/fileapi/Blob.cpp
diff --git a/third_party/WebKit/Source/core/fileapi/Blob.cpp b/third_party/WebKit/Source/core/fileapi/Blob.cpp
index 2cd6c87eda2e923e86de356a3000cbef872b5450..1de1f3f35003dad97879248e5a08f039b5d38aad 100644
--- a/third_party/WebKit/Source/core/fileapi/Blob.cpp
+++ b/third_party/WebKit/Source/core/fileapi/Blob.cpp
@@ -93,11 +93,6 @@ Blob* Blob::create(
const BlobPropertyBag& options,
ExceptionState& exceptionState) {
ASSERT(options.hasType());
- if (!options.type().containsOnlyASCII()) {
- exceptionState.throwDOMException(
- SyntaxError, "The 'type' property must consist of ASCII characters.");
- return nullptr;
- }
ASSERT(options.hasEndings());
bool normalizeLineEndingsToNative = options.endings() == "native";
@@ -105,7 +100,7 @@ Blob* Blob::create(
UseCounter::count(context, UseCounter::FileAPINativeLineEndings);
std::unique_ptr<BlobData> blobData = BlobData::create();
- blobData->setContentType(options.type().lower());
+ blobData->setContentType(normalizeType(options.type()));
populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative);
@@ -189,7 +184,7 @@ Blob* Blob::slice(long long start,
long long length = end - start;
std::unique_ptr<BlobData> blobData = BlobData::create();
- blobData->setContentType(contentType);
+ blobData->setContentType(normalizeType(contentType));
blobData->appendBlob(m_blobDataHandle, start, length);
return Blob::create(BlobDataHandle::create(std::move(blobData), length));
}
@@ -224,4 +219,25 @@ URLRegistry& Blob::registry() const {
return BlobURLRegistry::registry();
}
+// static
+String Blob::normalizeType(const String& type) {
+ if (type.isNull())
+ return emptyString;
+ const size_t length = type.length();
+ if (type.is8Bit()) {
+ const LChar* chars = type.characters8();
+ for (size_t i = 0; i < length; ++i) {
+ if (chars[i] < 0x20 || chars[i] > 0x7e)
+ return emptyString;
+ }
+ } else {
+ const UChar* chars = type.characters16();
+ for (size_t i = 0; i < length; ++i) {
+ if (chars[i] < 0x0020 || chars[i] > 0x007e)
+ return emptyString;
+ }
+ }
+ return type.lower();
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/Blob.h ('k') | third_party/WebKit/Source/core/fileapi/File.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698