From 959e85985bd66fae1d333b258762be9726232f50 Mon Sep 17 00:00:00 2001 From: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com> Date: Tue, 26 Apr 2022 15:01:19 +0200 Subject: [PATCH 1/4] Fixes #151 --- src/Smidge.Core/FileProcessors/RegexStatements.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Smidge.Core/FileProcessors/RegexStatements.cs b/src/Smidge.Core/FileProcessors/RegexStatements.cs index d44866a..1ba5717 100644 --- a/src/Smidge.Core/FileProcessors/RegexStatements.cs +++ b/src/Smidge.Core/FileProcessors/RegexStatements.cs @@ -6,7 +6,7 @@ namespace Smidge.FileProcessors public class RegexStatements { public static readonly Regex ImportCssRegex = new Regex(@"^\s*@import (url\((.+?)\)|[""'](.+?)[""'])\s*;?", RegexOptions.Compiled | RegexOptions.Multiline); - public static readonly Regex CssUrlRegex = new Regex(@"url\(((?![""']?data:|[""']?#).+?)\)", RegexOptions.Compiled); + public static readonly Regex CssUrlRegex = new Regex(@"url\(((?![""']?data:|[""']?#|[""']?%23).+?)\)", RegexOptions.Compiled); public static readonly Regex SourceMap = new Regex(@"^\s*//# sourceMappingURL=(.+?)(?:;|\s|$)", RegexOptions.Compiled); } -} \ No newline at end of file +} From 7e05aa132f3305a89319dd15eec5c8e8ccdd6742 Mon Sep 17 00:00:00 2001 From: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com> Date: Thu, 28 Apr 2022 11:22:38 +0200 Subject: [PATCH 2/4] Update CssUrlProcessorTests.cs --- test/Smidge.Tests/CssUrlProcessorTests.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/Smidge.Tests/CssUrlProcessorTests.cs b/test/Smidge.Tests/CssUrlProcessorTests.cs index 117e427..fd09d24 100644 --- a/test/Smidge.Tests/CssUrlProcessorTests.cs +++ b/test/Smidge.Tests/CssUrlProcessorTests.cs @@ -46,7 +46,11 @@ public void Ensure_Inline_Svg_Retained() var output = CssUrlProcessor.ReplaceUrlsWithAbsolutePaths(css, new Uri("http://MySite/MySubFolder")); Assert.Equal(css, output); - + + css = @"background-image: url('data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' width='1440' height='560' preserveAspectRatio='none' viewBox='0 0 1440 560'%3E%3Cg mask='url(%23SvgMask)' fill='none'%3E%3Crect width='1440' height='560' x='0' y='0' fill='%230e2a47'%3E%3C/rect%3E%3Cpath d='M0,299.673C72.712,301.383,144.361,356.897,211.698,329.408C280.324,301.393,325.188,229.231,346.476,158.23C366.61,91.077,336.011,22.497,324.451,-46.649C313.194,-113.982,329.935,-196.173,279.527,-242.212C228.756,-288.582,146.593,-255.806,79.411,-270.449C18.745,-283.672,-33.04,-325.944,-95.095,-323.865C-167.503,-321.439,-244.89,-307.587,-297.54,-257.82C-351.753,-206.576,-388.79,-128.697,-379.932,-54.626C-371.355,17.099,-283.43,50.028,-252.897,115.494C-222.761,180.11,-263.03,277.629,-205.396,319.602C-148.643,360.934,-70.19,298.023,0,299.673' fill='%230b2239'%3E%3C/path%3E%3Cpath d='M1440 918.348C1518.302 928.518 1598.121 948.7950000000001 1672.066 921.102 1754.284 890.3109999999999 1844.909 840.677 1871.125 756.888 1897.3809999999999 672.97 1811.973 595.333 1801.3020000000001 508.053 1790.275 417.863 1865.944 311.11199999999997 1808.061 241.07299999999998 1750.532 171.462 1636.261 200.72000000000003 1545.97 199.098 1476.288 197.846 1409.833 210.13400000000001 1343.906 232.735 1280.63 254.42700000000002 1225.146 287.336 1171.609 327.438 1104.7559999999999 377.514 1012.5889999999999 414.549 992.8340000000001 495.707 973.102 576.771 1027.513 657.944 1074.353 726.986 1116.136 788.5740000000001 1177.749 830.956 1243.689 865.466 1304.974 897.54 1371.405 909.4390000000001 1440 918.348' fill='%23113255'%3E%3C/path%3E%3C/g%3E%3Cdefs%3E%3Cmask id='SvgMask'%3E%3Crect width='1440' height='560' fill='%23ffffff'%3E%3C/rect%3E%3C/mask%3E%3C/defs%3E%3C/svg%3E"; + output = CssUrlProcessor.ReplaceUrlsWithAbsolutePaths(css, new Uri("http://MySite/MySubFolder")); + + Assert.Equal(css, output); } [Fact] From ef6c4ede784c4e3e651c15d67e2322c3d86581bb Mon Sep 17 00:00:00 2001 From: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com> Date: Thu, 28 Apr 2022 11:26:56 +0200 Subject: [PATCH 3/4] Update CssUrlProcessorTests.cs --- test/Smidge.Tests/CssUrlProcessorTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Smidge.Tests/CssUrlProcessorTests.cs b/test/Smidge.Tests/CssUrlProcessorTests.cs index fd09d24..c3a0e6d 100644 --- a/test/Smidge.Tests/CssUrlProcessorTests.cs +++ b/test/Smidge.Tests/CssUrlProcessorTests.cs @@ -47,7 +47,9 @@ public void Ensure_Inline_Svg_Retained() Assert.Equal(css, output); - css = @"background-image: url('data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' width='1440' height='560' preserveAspectRatio='none' viewBox='0 0 1440 560'%3E%3Cg mask='url(%23SvgMask)' fill='none'%3E%3Crect width='1440' height='560' x='0' y='0' fill='%230e2a47'%3E%3C/rect%3E%3Cpath d='M0,299.673C72.712,301.383,144.361,356.897,211.698,329.408C280.324,301.393,325.188,229.231,346.476,158.23C366.61,91.077,336.011,22.497,324.451,-46.649C313.194,-113.982,329.935,-196.173,279.527,-242.212C228.756,-288.582,146.593,-255.806,79.411,-270.449C18.745,-283.672,-33.04,-325.944,-95.095,-323.865C-167.503,-321.439,-244.89,-307.587,-297.54,-257.82C-351.753,-206.576,-388.79,-128.697,-379.932,-54.626C-371.355,17.099,-283.43,50.028,-252.897,115.494C-222.761,180.11,-263.03,277.629,-205.396,319.602C-148.643,360.934,-70.19,298.023,0,299.673' fill='%230b2239'%3E%3C/path%3E%3Cpath d='M1440 918.348C1518.302 928.518 1598.121 948.7950000000001 1672.066 921.102 1754.284 890.3109999999999 1844.909 840.677 1871.125 756.888 1897.3809999999999 672.97 1811.973 595.333 1801.3020000000001 508.053 1790.275 417.863 1865.944 311.11199999999997 1808.061 241.07299999999998 1750.532 171.462 1636.261 200.72000000000003 1545.97 199.098 1476.288 197.846 1409.833 210.13400000000001 1343.906 232.735 1280.63 254.42700000000002 1225.146 287.336 1171.609 327.438 1104.7559999999999 377.514 1012.5889999999999 414.549 992.8340000000001 495.707 973.102 576.771 1027.513 657.944 1074.353 726.986 1116.136 788.5740000000001 1177.749 830.956 1243.689 865.466 1304.974 897.54 1371.405 909.4390000000001 1440 918.348' fill='%23113255'%3E%3C/path%3E%3C/g%3E%3Cdefs%3E%3Cmask id='SvgMask'%3E%3Crect width='1440' height='560' fill='%23ffffff'%3E%3C/rect%3E%3C/mask%3E%3C/defs%3E%3C/svg%3E"; + css = @"body { + background-image: url('data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' width='1440' height='560' preserveAspectRatio='none' viewBox='0 0 1440 560'%3E%3Cg mask='url(%23SvgMask)' fill='none'%3E%3Crect width='1440' height='560' x='0' y='0' fill='%230e2a47'%3E%3C/rect%3E%3Cpath d='M0,299.673C72.712,301.383,144.361,356.897,211.698,329.408C280.324,301.393,325.188,229.231,346.476,158.23C366.61,91.077,336.011,22.497,324.451,-46.649C313.194,-113.982,329.935,-196.173,279.527,-242.212C228.756,-288.582,146.593,-255.806,79.411,-270.449C18.745,-283.672,-33.04,-325.944,-95.095,-323.865C-167.503,-321.439,-244.89,-307.587,-297.54,-257.82C-351.753,-206.576,-388.79,-128.697,-379.932,-54.626C-371.355,17.099,-283.43,50.028,-252.897,115.494C-222.761,180.11,-263.03,277.629,-205.396,319.602C-148.643,360.934,-70.19,298.023,0,299.673' fill='%230b2239'%3E%3C/path%3E%3Cpath d='M1440 918.348C1518.302 928.518 1598.121 948.7950000000001 1672.066 921.102 1754.284 890.3109999999999 1844.909 840.677 1871.125 756.888 1897.3809999999999 672.97 1811.973 595.333 1801.3020000000001 508.053 1790.275 417.863 1865.944 311.11199999999997 1808.061 241.07299999999998 1750.532 171.462 1636.261 200.72000000000003 1545.97 199.098 1476.288 197.846 1409.833 210.13400000000001 1343.906 232.735 1280.63 254.42700000000002 1225.146 287.336 1171.609 327.438 1104.7559999999999 377.514 1012.5889999999999 414.549 992.8340000000001 495.707 973.102 576.771 1027.513 657.944 1074.353 726.986 1116.136 788.5740000000001 1177.749 830.956 1243.689 865.466 1304.974 897.54 1371.405 909.4390000000001 1440 918.348' fill='%23113255'%3E%3C/path%3E%3C/g%3E%3Cdefs%3E%3Cmask id='SvgMask'%3E%3Crect width='1440' height='560' fill='%23ffffff'%3E%3C/rect%3E%3C/mask%3E%3C/defs%3E%3C/svg%3E); +}"; output = CssUrlProcessor.ReplaceUrlsWithAbsolutePaths(css, new Uri("http://MySite/MySubFolder")); Assert.Equal(css, output); From df293355acd1c55556f79970d24de12519aa0cdb Mon Sep 17 00:00:00 2001 From: PhyxionNL <7643972+PhyxionNL@users.noreply.github.com> Date: Thu, 28 Apr 2022 11:31:45 +0200 Subject: [PATCH 4/4] Add missing quotes --- test/Smidge.Tests/CssUrlProcessorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Smidge.Tests/CssUrlProcessorTests.cs b/test/Smidge.Tests/CssUrlProcessorTests.cs index c3a0e6d..b3653da 100644 --- a/test/Smidge.Tests/CssUrlProcessorTests.cs +++ b/test/Smidge.Tests/CssUrlProcessorTests.cs @@ -48,7 +48,7 @@ public void Ensure_Inline_Svg_Retained() Assert.Equal(css, output); css = @"body { - background-image: url('data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' width='1440' height='560' preserveAspectRatio='none' viewBox='0 0 1440 560'%3E%3Cg mask='url(%23SvgMask)' fill='none'%3E%3Crect width='1440' height='560' x='0' y='0' fill='%230e2a47'%3E%3C/rect%3E%3Cpath d='M0,299.673C72.712,301.383,144.361,356.897,211.698,329.408C280.324,301.393,325.188,229.231,346.476,158.23C366.61,91.077,336.011,22.497,324.451,-46.649C313.194,-113.982,329.935,-196.173,279.527,-242.212C228.756,-288.582,146.593,-255.806,79.411,-270.449C18.745,-283.672,-33.04,-325.944,-95.095,-323.865C-167.503,-321.439,-244.89,-307.587,-297.54,-257.82C-351.753,-206.576,-388.79,-128.697,-379.932,-54.626C-371.355,17.099,-283.43,50.028,-252.897,115.494C-222.761,180.11,-263.03,277.629,-205.396,319.602C-148.643,360.934,-70.19,298.023,0,299.673' fill='%230b2239'%3E%3C/path%3E%3Cpath d='M1440 918.348C1518.302 928.518 1598.121 948.7950000000001 1672.066 921.102 1754.284 890.3109999999999 1844.909 840.677 1871.125 756.888 1897.3809999999999 672.97 1811.973 595.333 1801.3020000000001 508.053 1790.275 417.863 1865.944 311.11199999999997 1808.061 241.07299999999998 1750.532 171.462 1636.261 200.72000000000003 1545.97 199.098 1476.288 197.846 1409.833 210.13400000000001 1343.906 232.735 1280.63 254.42700000000002 1225.146 287.336 1171.609 327.438 1104.7559999999999 377.514 1012.5889999999999 414.549 992.8340000000001 495.707 973.102 576.771 1027.513 657.944 1074.353 726.986 1116.136 788.5740000000001 1177.749 830.956 1243.689 865.466 1304.974 897.54 1371.405 909.4390000000001 1440 918.348' fill='%23113255'%3E%3C/path%3E%3C/g%3E%3Cdefs%3E%3Cmask id='SvgMask'%3E%3Crect width='1440' height='560' fill='%23ffffff'%3E%3C/rect%3E%3C/mask%3E%3C/defs%3E%3C/svg%3E); + background-image: url(""data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' width='1440' height='560' preserveAspectRatio='none' viewBox='0 0 1440 560'%3E%3Cg mask='url(%23SvgMask)' fill='none'%3E%3Crect width='1440' height='560' x='0' y='0' fill='%230e2a47'%3E%3C/rect%3E%3Cpath d='M0,299.673C72.712,301.383,144.361,356.897,211.698,329.408C280.324,301.393,325.188,229.231,346.476,158.23C366.61,91.077,336.011,22.497,324.451,-46.649C313.194,-113.982,329.935,-196.173,279.527,-242.212C228.756,-288.582,146.593,-255.806,79.411,-270.449C18.745,-283.672,-33.04,-325.944,-95.095,-323.865C-167.503,-321.439,-244.89,-307.587,-297.54,-257.82C-351.753,-206.576,-388.79,-128.697,-379.932,-54.626C-371.355,17.099,-283.43,50.028,-252.897,115.494C-222.761,180.11,-263.03,277.629,-205.396,319.602C-148.643,360.934,-70.19,298.023,0,299.673' fill='%230b2239'%3E%3C/path%3E%3Cpath d='M1440 918.348C1518.302 928.518 1598.121 948.7950000000001 1672.066 921.102 1754.284 890.3109999999999 1844.909 840.677 1871.125 756.888 1897.3809999999999 672.97 1811.973 595.333 1801.3020000000001 508.053 1790.275 417.863 1865.944 311.11199999999997 1808.061 241.07299999999998 1750.532 171.462 1636.261 200.72000000000003 1545.97 199.098 1476.288 197.846 1409.833 210.13400000000001 1343.906 232.735 1280.63 254.42700000000002 1225.146 287.336 1171.609 327.438 1104.7559999999999 377.514 1012.5889999999999 414.549 992.8340000000001 495.707 973.102 576.771 1027.513 657.944 1074.353 726.986 1116.136 788.5740000000001 1177.749 830.956 1243.689 865.466 1304.974 897.54 1371.405 909.4390000000001 1440 918.348' fill='%23113255'%3E%3C/path%3E%3C/g%3E%3Cdefs%3E%3Cmask id='SvgMask'%3E%3Crect width='1440' height='560' fill='%23ffffff'%3E%3C/rect%3E%3C/mask%3E%3C/defs%3E%3C/svg%3E""); }"; output = CssUrlProcessor.ReplaceUrlsWithAbsolutePaths(css, new Uri("http://MySite/MySubFolder"));