Commit 6ab09daa9 for imagemagick.org

commit 6ab09daa92258352f4f9a8ae54c5b49b55d9d9cc
Author: Arham Amin <132888838+arhxam@users.noreply.github.com>
Date:   Sun Aug 23 19:34:42 2026 +0530

    Fix inline SVG style precedence (#8920)

diff --git a/coders/svg.c b/coders/svg.c
index 879fcc694..3a68547c8 100644
--- a/coders/svg.c
+++ b/coders/svg.c
@@ -1279,6 +1279,7 @@ static void SVGStartElement(void *context,const xmlChar *name,
     background[MagickPathExtent],
     id[MagickPathExtent],
     *next_token,
+    *style,
     token[MagickPathExtent],
     **tokens,
     *units;
@@ -1325,6 +1326,7 @@ static void SVGStartElement(void *context,const xmlChar *name,
     }
   svg_info->scale[svg_info->n]=svg_info->scale[svg_info->n-1];
   color=AcquireString("none");
+  style=(char *) NULL;
   units=AcquireString("userSpaceOnUse");
   *id='\0';
   *token='\0';
@@ -2252,7 +2254,7 @@ static void SVGStartElement(void *context,const xmlChar *name,
             }
           if (LocaleCompare(keyword,"style") == 0)
             {
-              SVGProcessStyleElement(svg_info,name,value);
+              (void) CloneString(&style,value);
               break;
             }
           break;
@@ -2559,6 +2561,11 @@ static void SVGStartElement(void *context,const xmlChar *name,
       }
       value=DestroyString(value);
     }
+  if (style != (char *) NULL)
+    {
+      SVGProcessStyleElement(svg_info,name,style);
+      style=DestroyString(style);
+    }
   if (LocaleCompare((const char *) name,"svg") == 0)
     {
       if (parser->encoding != (const xmlChar *) NULL)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8a031716c..e0cf6c506 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -62,6 +62,7 @@ TESTS_EXTRA_DIST = \
   tests/common.shi \
   tests/rose.pnm \
   tests/input_svg_gradient_transform.svg \
+  tests/input_svg_inline_style.svg \
   tests/input_256c.miff \
   tests/input_bilevel.miff \
   tests/input_gray.miff \
diff --git a/tests/cli-svg.tap b/tests/cli-svg.tap
index 033280217..882483c07 100755
--- a/tests/cli-svg.tap
+++ b/tests/cli-svg.tap
@@ -18,8 +18,19 @@
 #
 . ./common.shi
 . ${srcdir}/tests/common.shi
-echo "1..1"
+echo "1..2"

 # gradientTransform should not cause a double-free / SIGABRT (#8582)
 ${MAGICK} ${SRCDIR}/input_svg_gradient_transform.svg null: && echo "ok" || echo "not ok"
+
+# Inline styles override presentation attributes regardless of attribute order.
+msvg_mode=`${MAGICK} -list format | awk '$1 ~ /^MSVG/ { print $2 }'`
+case "$msvg_mode" in
+  *r*)
+    colors=`${MAGICK} MSVG:${SRCDIR}/input_svg_inline_style.svg \
+      -format '%[fx:int(255*p{5,5}.r+0.5)],%[fx:int(255*p{5,5}.g+0.5)],%[fx:int(255*p{5,5}.b+0.5)] %[fx:int(255*p{15,5}.r+0.5)],%[fx:int(255*p{15,5}.g+0.5)],%[fx:int(255*p{15,5}.b+0.5)]' info:-`
+    [ "X$colors" = "X255,255,255 255,255,255" ] && echo "ok" || echo "not ok"
+    ;;
+  *) echo "ok # SKIP MSVG coder unavailable" ;;
+esac
 :
diff --git a/tests/input_svg_inline_style.svg b/tests/input_svg_inline_style.svg
new file mode 100644
index 000000000..b236c0b93
--- /dev/null
+++ b/tests/input_svg_inline_style.svg
@@ -0,0 +1,6 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="20" height="10">
+  <rect x="0" y="0" width="10" height="10"
+    style="fill:#ffffff" fill="#d6a312"/>
+  <rect x="10" y="0" width="10" height="10"
+    fill="#d6a312" style="fill:#ffffff"/>
+</svg>