LibWeb: Return empty string if image element currentSrc URL is invalid

This commit is contained in:
Tim Ledbetter 2024-08-14 23:52:11 +01:00 committed by Andreas Kling
commit 4f7a4d9c57
Notes: github-actions[bot] 2024-08-15 07:45:34 +00:00
3 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1 @@
img.currentSrc default value: ''

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
test(() => {
const elementList = [
{ "img": "currentSrc" },
];
for (const elementDescriptor of elementList) {
[elementName, propertyName] = Object.entries(elementDescriptor)[0];
const element = document.createElement(elementName);
println(`${elementName}.${propertyName} default value: '${element[propertyName]}'`);
}
});
</script>

View file

@ -275,7 +275,10 @@ bool HTMLImageElement::complete() const
String HTMLImageElement::current_src() const
{
// The currentSrc IDL attribute must return the img element's current request's current URL.
return MUST(m_current_request->current_url().to_string());
auto current_url = m_current_request->current_url();
if (!current_url.is_valid())
return {};
return MUST(current_url.to_string());
}
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-decode