css: Don't throw warnings on broken URL in image css

If a URL can't be loaded, we might end up with a NULL file. Handle that
case properly by creating an invalid image instead and don't crash or
complain to stderr when files are NULL.

This was broken since 0886ade182

A new reftest has been included. We need a reftest instead of a
CSS parser test, because the error only becomes visible when
compute()ing the actual image.

Fixes #4373


(cherry picked from commit ac8c4245b2)
This commit is contained in:
Benjamin Otte
2021-10-26 17:02:56 +02:00
committed by Benjamin Otte
parent 4f5264d1b7
commit 36cb2e932c
5 changed files with 34 additions and 0 deletions

View File

@@ -42,6 +42,12 @@ gtk_css_image_url_load_image (GtkCssImageUrl *url,
if (url->loaded_image)
return url->loaded_image;
if (url->file == NULL)
{
url->loaded_image = gtk_css_image_invalid_new ();
return url->loaded_image;
}
/* We special case resources here so we can use gdk_texture_new_from_resource. */
if (g_file_has_uri_scheme (url->file, "resource"))
{
@@ -148,6 +154,10 @@ gtk_css_image_url_equal (GtkCssImage *image1,
{
GtkCssImageUrl *url1 = GTK_CSS_IMAGE_URL (image1);
GtkCssImageUrl *url2 = GTK_CSS_IMAGE_URL (image2);
/* FIXME: We don't save data: urls, so we can't compare them here */
if (url1->file == NULL || url2->file == NULL)
return FALSE;
return g_file_equal (url1->file, url2->file);
}

View File

@@ -0,0 +1,4 @@
#test {
/* The url should fail as early as possible */
background-image: url('data::::');
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="width_request">10</property>
<property name="height_request">10</property>
<property name="decorated">0</property>
</object>
</interface>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="width_request">10</property>
<property name="height_request">10</property>
<property name="decorated">0</property>
<property name="name">test</property>
</object>
</interface>

View File

@@ -191,6 +191,9 @@ testdata = [
'css-image-aspect-ratio.css',
'css-image-aspect-ratio.ui',
'css-image-aspect-ratio.ref.ui',
'css-image-broken-url.css',
'css-image-broken-url.ref.ui',
'css-image-broken-url.ui',
'css-image-color-aspect-ratio.css',
'css-image-color-aspect-ratio.ui',
'css-image-color-aspect-ratio.ref.ui',