From 280bb6ab6bd460db71168611b4daff153cfa7b7e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 31 Jul 2025 10:05:00 +0000 Subject: [PATCH 1/2] Add backward-compatible method overloads for MoveCssInline to fix binary compatibility issue Co-authored-by: martinnormark <67565+martinnormark@users.noreply.github.com> --- PreMailer.Net/Benchmarks/Benchmarks.csproj | 2 +- .../PreMailer.Net.Tests.csproj | 2 +- .../PreMailer.Net.Tests/PreMailerTests.cs | 69 +++++++++++++++ PreMailer.Net/PreMailer.Net/PreMailer.cs | 88 +++++++++++++++++++ 4 files changed, 159 insertions(+), 2 deletions(-) diff --git a/PreMailer.Net/Benchmarks/Benchmarks.csproj b/PreMailer.Net/Benchmarks/Benchmarks.csproj index 22100bf..135d529 100644 --- a/PreMailer.Net/Benchmarks/Benchmarks.csproj +++ b/PreMailer.Net/Benchmarks/Benchmarks.csproj @@ -2,7 +2,7 @@ Exe - net9.0 + net8.0 enable diff --git a/PreMailer.Net/PreMailer.Net.Tests/PreMailer.Net.Tests.csproj b/PreMailer.Net/PreMailer.Net.Tests/PreMailer.Net.Tests.csproj index ec4074c..b732c45 100644 --- a/PreMailer.Net/PreMailer.Net.Tests/PreMailer.Net.Tests.csproj +++ b/PreMailer.Net/PreMailer.Net.Tests/PreMailer.Net.Tests.csproj @@ -1,7 +1,7 @@ - net9.0 + net8.0 false diff --git a/PreMailer.Net/PreMailer.Net.Tests/PreMailerTests.cs b/PreMailer.Net/PreMailer.Net.Tests/PreMailerTests.cs index 179f947..c523d24 100644 --- a/PreMailer.Net/PreMailer.Net.Tests/PreMailerTests.cs +++ b/PreMailer.Net/PreMailer.Net.Tests/PreMailerTests.cs @@ -710,5 +710,74 @@ public void MoveCssInline_EmptyTagsArePreserved() Assert.DoesNotContain("", premailedOutput.Html); Assert.DoesNotContain("", premailedOutput.Html); } + + [Fact] + public void MoveCssInline_BackwardCompatibility_StaticMethod_WithoutUseEmailFormatter() + { + // Test that the old method signature (without useEmailFormatter) still works + string input = "
test
"; + + // This should call the backward-compatible overload + var premailedOutput = PreMailer.MoveCssInline(input, false, null, null, false, false, null, false); + + Assert.Contains("
.test { height: 100px; }
test
"; + + var premailer = new PreMailer(input); + // This should call the backward-compatible instance method overload + var premailedOutput = premailer.MoveCssInline(false, null, null, false, false, null, false); + + Assert.Contains("
.test { height: 100px; }
test
"; + + using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(input))) + { + // This should call the backward-compatible Stream overload + var premailedOutput = PreMailer.MoveCssInline(stream, false, null, null, false, false, null, false); + + Assert.Contains("
.test { height: 100px; }
test
"; + var baseUri = new Uri("http://example.com/"); + + // This should call the backward-compatible Uri overload + var premailedOutput = PreMailer.MoveCssInline(baseUri, input, false, null, null, false, false, null, false); + + Assert.Contains("
.test { height: 100px; }
test
"; + var baseUri = new Uri("http://example.com/"); + + using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(input))) + { + // This should call the backward-compatible Uri + Stream overload + var premailedOutput = PreMailer.MoveCssInline(baseUri, stream, false, null, null, false, false, null, false); + + Assert.Contains("
+ /// In-lines the CSS within the HTML given. + /// + /// The HTML input. + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public static InlineResult MoveCssInline(string html, bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return new PreMailer(html).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS within the HTML given. /// @@ -86,6 +103,23 @@ public static InlineResult MoveCssInline(string html, bool removeStyleElements = return new PreMailer(html).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, useEmailFormatter); } + /// + /// In-lines the CSS within the HTML given. + /// + /// The Stream input. + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public static InlineResult MoveCssInline(Stream stream, bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return new PreMailer(stream).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS within the HTML given. /// @@ -104,6 +138,25 @@ public static InlineResult MoveCssInline(Stream stream, bool removeStyleElements return new PreMailer(stream).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, useEmailFormatter); } + /// + /// In-lines the CSS within the HTML given. + /// + /// /// The base url that will be used to resolve any relative urls + /// The Url that all relative urls will be off of. + /// The HTML input. + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public static InlineResult MoveCssInline(Uri baseUri, string html, bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return new PreMailer(html, baseUri).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS within the HTML given. /// @@ -124,6 +177,25 @@ public static InlineResult MoveCssInline(Uri baseUri, string html, bool removeSt return new PreMailer(html, baseUri).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, useEmailFormatter); } + /// + /// In-lines the CSS within the HTML given. + /// + /// /// The base url that will be used to resolve any relative urls + /// The Url that all relative urls will be off of. + /// The HTML input. + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public static InlineResult MoveCssInline(Uri baseUri, Stream stream, bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return new PreMailer(stream, baseUri).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS within the HTML given. /// @@ -144,6 +216,22 @@ public static InlineResult MoveCssInline(Uri baseUri, Stream stream, bool remove return new PreMailer(stream, baseUri).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, useEmailFormatter); } + /// + /// In-lines the CSS for the current HTML + /// + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public InlineResult MoveCssInline(bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS for the current HTML /// From fefd11cf4603eb17a4a3317fec647ee03860086c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20H=C3=B8st=20Normark?= Date: Mon, 25 Aug 2025 08:15:17 +0200 Subject: [PATCH 2/2] Revert target framework change --- PreMailer.Net/Benchmarks/Benchmarks.csproj | 2 +- PreMailer.Net/PreMailer.Net.Tests/PreMailer.Net.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PreMailer.Net/Benchmarks/Benchmarks.csproj b/PreMailer.Net/Benchmarks/Benchmarks.csproj index 135d529..22100bf 100644 --- a/PreMailer.Net/Benchmarks/Benchmarks.csproj +++ b/PreMailer.Net/Benchmarks/Benchmarks.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 enable diff --git a/PreMailer.Net/PreMailer.Net.Tests/PreMailer.Net.Tests.csproj b/PreMailer.Net/PreMailer.Net.Tests/PreMailer.Net.Tests.csproj index b732c45..ec4074c 100644 --- a/PreMailer.Net/PreMailer.Net.Tests/PreMailer.Net.Tests.csproj +++ b/PreMailer.Net/PreMailer.Net.Tests/PreMailer.Net.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 false