diff options
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/tests/blob_test.ts | 8 | ||||
-rw-r--r-- | cli/js/web/blob.ts | 25 |
2 files changed, 20 insertions, 13 deletions
diff --git a/cli/js/tests/blob_test.ts b/cli/js/tests/blob_test.ts index 57793af0e..b60877dd0 100644 --- a/cli/js/tests/blob_test.ts +++ b/cli/js/tests/blob_test.ts @@ -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; diff --git a/cli/js/web/blob.ts b/cli/js/web/blob.ts index 5309ddaf4..c4e4674ab 100644 --- a/cli/js/web/blob.ts +++ b/cli/js/web/blob.ts @@ -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; |