Repository: microsoft/PowerToys
File: src/modules/previewpane/common/Utilities/SvgPreviewHandlerHelper.cs (C#)

Code before:
        /// If there is a CSS unit at the end return the same string, else return the string with a px unit at the end
        /// </summary>
        /// <param name="length">CSS length</param>
        /// <returns>Returns modified length</returns>
        private static string CheckUnit(string length)
        {
            string[] cssUnits = { "cm", "mm", "in", "px", "pt", "pc", "em", "ex", "ch", "rem", "vw", "vh", "vmin", "vmax", "%" };
            foreach (var unit in cssUnits)
            {
                if (length.EndsWith(unit, System.StringComparison.CurrentCultureIgnoreCase))
                {
                    return length;
                }
            }

            return length + "px";
        }

        /// <summary>
        /// Swaps positions of default and svg namespace definitions if default namespace comes first in original SVG data
        /// </summary>
        /// <param name="svgData">SVG data</param>
        /// <returns>Returns modified SVG data</returns>
        public static string SwapNamespaces(string svgData)
        {
            const string defaultNamespacePrefix = "xmlns=\"";
            const string svgNamespacePrefix = "xmlns:svg=\"";

            int defaultNamespacePrefixIndex = svgData.IndexOf(defaultNamespacePrefix, StringComparison.InvariantCultureIgnoreCase);
            int svgNamespacePrefixIndex = svgData.IndexOf(svgNamespacePrefix, StringComparison.InvariantCultureIgnoreCase);

            if (defaultNamespacePrefixIndex != -1 && svgNamespacePrefixIndex != -1 && defaultNamespacePrefixIndex < svgNamespacePrefixIndex)
            {
                int defaultNamespaceEndIndex = svgData.IndexOf("\"", defaultNamespacePrefixIndex + defaultNamespacePrefix.Length, StringComparison.InvariantCultureIgnoreCase);
                int svgNamespaceEndIndex = svgData.IndexOf("\"", svgNamespacePrefixIndex + svgNamespacePrefix.Length, StringComparison.InvariantCultureIgnoreCase);
                string defaultNamespace = svgData.Substring(defaultNamespacePrefixIndex, defaultNamespaceEndIndex - defaultNamespacePrefixIndex + 1);
                string svgNamespace = svgData.Substring(svgNamespacePrefixIndex, svgNamespaceEndIndex - svgNamespacePrefixIndex + 1);

                svgData = svgData.Replace(defaultNamespace, "{0}", StringComparison.InvariantCultureIgnoreCase);
                svgData = svgData.Replace(svgNamespace, "{1}", StringComparison.InvariantCultureIgnoreCase);
                svgData = string.Format(CultureInfo.InvariantCulture, svgData, svgNamespace, defaultNamespace);
            }

            return svgData;
        }

        /// <summary>
        /// Remove a CSS unit from the end of the string
        /// </summary>
        /// <param name="length">CSS length</param>
        /// <returns>Returns modified length</returns>

Review comment (suggestion):
Wonder if this can cause issues on some cases we're not aware. It'd be safer to look for the bigger strings, since it's always going to be the same, right? `xmlns="http://www.w3.org/2000/svg"` and `xmlns:svg="http://www.w3.org/2000/svg"`

Code after:
        /// If there is a CSS unit at the end return the same string, else return the string with a px unit at the end
        /// </summary>
        /// <param name="length">CSS length</param>
        /// <returns>Returns modified length</returns>
        private static string CheckUnit(string length)
        {
            string[] cssUnits = { "cm", "mm", "in", "px", "pt", "pc", "em", "ex", "ch", "rem", "vw", "vh", "vmin", "vmax", "%" };
            foreach (var unit in cssUnits)
            {
                if (length.EndsWith(unit, System.StringComparison.CurrentCultureIgnoreCase))
                {
                    return length;
                }
            }

            return length + "px";
        }

        /// <summary>
        /// Swaps positions of default and svg namespace definitions if default namespace comes first in original SVG data
        /// </summary>
        /// <param name="svgData">SVG data</param>
        /// <returns>Returns modified SVG data</returns>
        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;
        }

        /// <summary>
        /// Remove a CSS unit from the end of the string
        /// </summary>
        /// <param name="length">CSS length</param>
        /// <returns>Returns modified length</returns>
        private static string RemoveUnit(string length)
        {
            string[] cssUnits = { "cm", "mm", "in", "px", "pt", "pc", "em", "ex", "ch", "rem", "vw", "vh", "vmin", "vmax", "%" };
            foreach (var unit in cssUnits)
            {