diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt
index a00bf165d1..731fa0aca8 100644
--- a/.github/actions/spell-check/expect.txt
+++ b/.github/actions/spell-check/expect.txt
@@ -616,6 +616,7 @@ Filterx
finalizer
findfast
findstr
+Firefox
FIXEDFILEINFO
FLASHZONES
FLASHZONESONQUICKSWITCH
@@ -886,6 +887,7 @@ ingbuffer
inheritdoc
INITDIALOG
initguid
+Inkscape
Inlines
inorder
INotification
diff --git a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs
index ad6d262f60..5d5cefb234 100644
--- a/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs
+++ b/src/modules/previewpane/SvgPreviewHandler/SvgPreviewControl.cs
@@ -102,6 +102,10 @@ namespace Microsoft.PowerToys.PreviewHandler.Svg
try
{
+ // Fixes #17527 - Inkscape v1.1 swapped order of default and svg namespaces in svg file (default first, svg after).
+ // That resulted in parser being unable to parse it correctly and instead of svg, text was previewed.
+ // MS Edge and Firefox also couldn't preview svg files with mentioned order of namespaces definitions.
+ svgData = SvgPreviewHandlerHelper.SwapNamespaces(svgData);
svgData = SvgPreviewHandlerHelper.AddStyleSVG(svgData);
}
catch (Exception ex)
diff --git a/src/modules/previewpane/common/Utilities/SvgPreviewHandlerHelper.cs b/src/modules/previewpane/common/Utilities/SvgPreviewHandlerHelper.cs
index e245a0777d..2fbc91e7a5 100644
--- a/src/modules/previewpane/common/Utilities/SvgPreviewHandlerHelper.cs
+++ b/src/modules/previewpane/common/Utilities/SvgPreviewHandlerHelper.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Xml.Linq;
@@ -154,6 +155,29 @@ namespace Common.Utilities
return length + "px";
}
+ ///
+ /// Swaps positions of default and svg namespace definitions if default namespace comes first in original SVG data
+ ///
+ /// SVG data
+ /// Returns modified SVG data
+ public static string SwapNamespaces(string svgData)
+ {
+ const string defaultNamespace = "xmlns=\"http://www.w3.org/2000/svg\"";
+ const string svgNamespace = "xmlns:svg=\"http://www.w3.org/2000/svg\"";
+
+ int defaultNamespaceIndex = svgData.IndexOf(defaultNamespace, StringComparison.InvariantCultureIgnoreCase);
+ int svgNamespaceIndex = svgData.IndexOf(svgNamespace, StringComparison.InvariantCultureIgnoreCase);
+
+ if (defaultNamespaceIndex != -1 && svgNamespaceIndex != -1 && defaultNamespaceIndex < svgNamespaceIndex)
+ {
+ svgData = svgData.Replace(defaultNamespace, "{0}", StringComparison.InvariantCultureIgnoreCase);
+ svgData = svgData.Replace(svgNamespace, "{1}", StringComparison.InvariantCultureIgnoreCase);
+ svgData = string.Format(CultureInfo.InvariantCulture, svgData, svgNamespace, defaultNamespace);
+ }
+
+ return svgData;
+ }
+
///
/// Remove a CSS unit from the end of the string
///