[gtk/cherry-pick-ac8c4245] css: Don't throw warnings on broken URL in image css




commit 36cb2e932c7d610c4e8a02e29e912a8b501f256b
Author: Benjamin Otte <otte redhat com>
Date:   Tue Oct 26 17:02:56 2021 +0200

    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 0886ade182f1a958024202d5c20248d57fcdb053
    
    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 ac8c4245b2fb2f1fe8e660c4ad2541efb39cf3d6)

 gtk/gtkcssimageurl.c                           | 10 ++++++++++
 testsuite/reftests/css-image-broken-url.css    |  4 ++++
 testsuite/reftests/css-image-broken-url.ref.ui |  8 ++++++++
 testsuite/reftests/css-image-broken-url.ui     |  9 +++++++++
 testsuite/reftests/meson.build                 |  3 +++
 5 files changed, 34 insertions(+)
---
diff --git a/gtk/gtkcssimageurl.c b/gtk/gtkcssimageurl.c
index d7271eda18..f201dcb841 100644
--- a/gtk/gtkcssimageurl.c
+++ b/gtk/gtkcssimageurl.c
@@ -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);
 }
diff --git a/testsuite/reftests/css-image-broken-url.css b/testsuite/reftests/css-image-broken-url.css
new file mode 100644
index 0000000000..d7035a5e6d
--- /dev/null
+++ b/testsuite/reftests/css-image-broken-url.css
@@ -0,0 +1,4 @@
+#test {
+  /* The url should fail as early as possible */
+  background-image: url('data::::');
+}
diff --git a/testsuite/reftests/css-image-broken-url.ref.ui b/testsuite/reftests/css-image-broken-url.ref.ui
new file mode 100644
index 0000000000..3c0e77e927
--- /dev/null
+++ b/testsuite/reftests/css-image-broken-url.ref.ui
@@ -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>
diff --git a/testsuite/reftests/css-image-broken-url.ui b/testsuite/reftests/css-image-broken-url.ui
new file mode 100644
index 0000000000..286c35fe09
--- /dev/null
+++ b/testsuite/reftests/css-image-broken-url.ui
@@ -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>
diff --git a/testsuite/reftests/meson.build b/testsuite/reftests/meson.build
index c166233ad9..0d078fd9dd 100644
--- a/testsuite/reftests/meson.build
+++ b/testsuite/reftests/meson.build
@@ -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',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]