Skip to content

Commit

Permalink
fix: invalid blob type (denoland#4536)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats authored Mar 31, 2020
1 parent d4d0b5d commit 7b675a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
8 changes: 8 additions & 0 deletions cli/js/tests/blob_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ unitTest(function blobSlice(): void {
assertEquals(b4.size, blob.size);
});

unitTest(function blobInvalidType(): void {
const blob = new Blob(["foo"], {
type: "\u0521",
});

assertEquals(blob.type, "");
});

unitTest(function blobShouldNotThrowError(): void {
let hasThrown = false;

Expand Down
25 changes: 12 additions & 13 deletions cli/js/web/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,23 @@ export class DenoBlob implements domTypes.Blob {
}

const { ending = "transparent", type = "" } = options ?? {};
if (!containsOnlyASCII(type)) {
const errMsg = "The 'type' property must consist of ASCII characters.";
throw new SyntaxError(errMsg);
}

const bytes = processBlobParts(blobParts!, { ending, type });
// Normalize options.type.
let normalizedType = type;
if (type.length) {
for (let i = 0; i < type.length; ++i) {
const char = type[i];
if (char < "\u0020" || char > "\u007E") {
normalizedType = "";
break;
if (!containsOnlyASCII(type)) {
normalizedType = "";
} else {
if (type.length) {
for (let i = 0; i < type.length; ++i) {
const char = type[i];
if (char < "\u0020" || char > "\u007E") {
normalizedType = "";
break;
}
}
normalizedType = type.toLowerCase();
}
normalizedType = type.toLowerCase();
}
const bytes = processBlobParts(blobParts!, { ending, type });
// Set Blob object's properties.
this[bytesSymbol] = bytes;
this.size = bytes.byteLength;
Expand Down

0 comments on commit 7b675a3

Please sign in to comment.