Skip to content

Commit 4649b1a

Browse files
Merge pull request #139 from nbajko/master
Fix issue #138 - Duplicated style properties added with different values
2 parents 025bbd2 + 330c5ef commit 4649b1a

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

PreMailer.Net/PreMailer.Net.Tests/CssParserTests.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,32 @@ public void AddStylesheet_ShouldSetStyleClassPositions()
170170
Assert.AreEqual(1, parser.Styles.Values[0].Position);
171171
Assert.AreEqual(4, parser.Styles.Values[1].Position);
172172
Assert.AreEqual(3, parser.Styles.Values[2].Position);
173-
}
174-
}
173+
}
174+
175+
[TestMethod]
176+
public void AddStylesheet_ContainsSingleQuotes_ShouldParseStylesheet()
177+
{
178+
var stylesheet = "a { color: #fff; font-family: 'Segoe UI', Verdana, Arial, sans-serif; text-decoration: underline; }";
179+
var parser = new CssParser();
180+
181+
parser.AddStyleSheet(stylesheet);
182+
183+
Assert.IsNotNull(parser.Styles["a"]);
184+
Assert.IsNotNull(parser.Styles["a"].Attributes["font-family"]);
185+
Assert.AreEqual(3, parser.Styles["a"].Attributes.Count);
186+
}
187+
188+
[TestMethod]
189+
public void AddStylesheet_ContainsDoubleQuotes_ShouldParseStylesheet()
190+
{
191+
var stylesheet = "a { color: #fff; font-family: \"Segoe UI\", Verdana, Arial, sans-serif; text-decoration: underline; }";
192+
var parser = new CssParser();
193+
194+
parser.AddStyleSheet(stylesheet);
195+
196+
Assert.IsNotNull(parser.Styles["a"]);
197+
Assert.IsNotNull(parser.Styles["a"].Attributes["font-family"]);
198+
Assert.AreEqual(3, parser.Styles["a"].Attributes.Count);
199+
}
200+
}
175201
}

PreMailer.Net/PreMailer.Net/CssParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void FillStyleClass(StyleClass sc, string styleName, string style)
109109
}
110110
}
111111

112-
private static Regex FillStyleClassRegex = new Regex(@"(;)(?=(?:[^""']|[""|'][^""']*"")*$)", RegexOptions.Multiline | RegexOptions.Compiled);
112+
private static Regex FillStyleClassRegex = new Regex(@"(;)(?=(?:[^""']|""[^""]*""|'[^']*')*$)", RegexOptions.Multiline | RegexOptions.Compiled);
113113
private static Regex CssCommentRegex = new Regex(@"(?:/\*(.|[\r\n])*?\*/)|(?:(?<!url\s*\([^)]*)//.*)", RegexOptions.Compiled);
114114
private static Regex UnsupportedAtRuleRegex = new Regex(@"(?:@charset [^;]*;)|(?:@(page|font-face)[^{]*{[^}]*})|@import.+?;", RegexOptions.IgnoreCase | RegexOptions.Compiled);
115115

@@ -135,4 +135,4 @@ private string CleanupMediaQueries(string s)
135135
return temp;
136136
}
137137
}
138-
}
138+
}

0 commit comments

Comments
 (0)