Skip to content

blob: slice() without valid content type yields unexpected results #177

@dlrobertson

Description

@dlrobertson

Based on my reading of blob.slice(), it seems that the resulting blobs content type should be the empty string under the following cases:

  1. contentType is not given
  2. contentType has a value outside the range of U+0020 to U+007E

After writing a simple wpt test, it seems like no browser does 1 and only one does 2.

Test Safari Chrome Firefox
no contentType
bad contentType

Just in case the issue is actually my test cases 😄, I've attached the example I used below:

promise_test(function(test) {
  var blob = new Blob(["this has no content type"]);
  let slice = blob.slice(12, 24, "\0");
  return fetch(URL.createObjectURL(slice)).then(function (resp) {
    assert_equals(resp.status, 200, "HTTP status is 200");
    assert_equals(resp.type, "basic", "response type is basic");
    assert_equals(resp.headers.get("Content-Type"), "");
    assert_equals(resp.headers.get("Content-Length"), "12");
    return resp.text();
  }).then(function(bodyAsText) {
    assert_equals("content type", bodyAsText)
  });
}, "Set content type to the empty string for slice with invalid content type");

promise_test(function(test) {
  var blob = new Blob(["this has a content type"], {"type": "application/xml"});
  let slice = blob.slice(11, 23);
  return fetch(URL.createObjectURL(slice)).then(function (resp) {
    assert_equals(resp.status, 200, "HTTP status is 200");
    assert_equals(resp.type, "basic", "response type is basic");
    assert_equals(resp.headers.get("Content-Type"), "");
    assert_equals(resp.headers.get("Content-Length"), "12");
    return resp.text();
  }).then(function(bodyAsText) {
    assert_equals("content type", bodyAsText)
  });
}, "Set content type to the empty string for slice with no content type ");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions