Skip to content

Truly independent web browser

LibWeb: Load an object element’s bodiless response as empty data

sideshowbarkerc90f9f1391cf
diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp
index 3e6814a6665..4a942246598 100644
--- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp
@@ -314,7 +314,11 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()
self.resource_did_fail();
});
- VERIFY(response->body());
+ // NB: A response without a body, such as a 204, has nothing to read: Its data is empty.
+ if (!response->body()) {
+ self.resource_did_load(response, {});
+ return;
+ }
response->body()->fully_read(realm, on_data_read, on_error, GC::Ref { global });
});
@@ -492,7 +496,10 @@ void HTMLObjectElement::run_object_representation_handler_steps(Fetch::Infrastru
// The object element represents the specified image.
// If the image cannot be rendered, e.g. because it is malformed or in an unsupported format, jump to the step
// below labeled fallback.
+ // AD-HOC: The spec only jumps to fallback here. But an empty image is a resource that failed to load, so fire
+ // error first, as for any other.
if (data.is_empty()) {
+ dispatch_event(create_event_for_element(*this, HTML::EventNames::error));
run_object_representation_fallback_steps();
return;
}
diff --git a/Tests/LibWeb/Text/expected/HTML/object-element-response-without-body.txt b/Tests/LibWeb/Text/expected/HTML/object-element-response-without-body.txt
new file mode 100644
index 00000000000..07ec231a481
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/object-element-response-without-body.txt
@@ -0,0 +1,3 @@
+typed image/png: error
+untyped: error
+untyped, with Content-Type image/png: error
diff --git a/Tests/LibWeb/Text/input/HTML/object-element-response-without-body.html b/Tests/LibWeb/Text/input/HTML/object-element-response-without-body.html
new file mode 100644
index 00000000000..27012b794bb
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/object-element-response-without-body.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ // A 204 response has a null body rather than an empty one, so the object element has nothing to read, and gets
+ // empty data, which it can't display.
+ asyncTest(async done => {
+ const server = httpTestServer();
+ const url = await server.createEcho("GET", "/object-element-response-without-body", { status: 204 });
+ const imageUrl = await server.createEcho("GET", "/object-element-image-response-without-body", {
+ status: 204,
+ headers: { "Content-Type": "image/png" },
+ });
+ const results = [];
+ for (const [description, data, type] of [
+ ["typed image/png", url, "image/png"],
+ ["untyped", url, ""],
+ ["untyped, with Content-Type image/png", imageUrl, ""],
+ ]) {
+ const object = document.createElement("object");
+ if (type)
+ object.type = type;
+ object.data = data;
+ results.push(new Promise(resolve => {
+ object.onload = () => resolve(`${description}: load`);
+ object.onerror = () => resolve(`${description}: error`);
+ }));
+ document.body.appendChild(object);
+ }
+ for (const result of await Promise.all(results))
+ println(result);
+ done();
+ });
+</script>