Skip to content

Commit db9e1a1

Browse files
author
ArthurHub
committed
* fix case-senssitive url in css not working properly
1 parent 4c2ed79 commit db9e1a1

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Source/HtmlRenderer/Parse/CssParser.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ public static void ParseStyleSheet(CssData cssData, string stylesheet)
6666
{
6767
if (!String.IsNullOrEmpty(stylesheet))
6868
{
69-
// Convert everything to lower-case so not to handle case in code
70-
stylesheet = stylesheet.ToLower();
71-
7269
stylesheet = RemoveStylesheetComments(stylesheet);
7370

7471
ParseStyleBlocks(cssData, stylesheet);
@@ -85,9 +82,6 @@ public static void ParseStyleSheet(CssData cssData, string stylesheet)
8582
/// <returns>the created CSS block instance</returns>
8683
public static CssBlock ParseCssBlock(string className, string blockSource)
8784
{
88-
// Convert everything to lower-case so not to handle case in code
89-
blockSource = blockSource.ToLower();
90-
9185
return ParseCssBlockImp(className, blockSource);
9286
}
9387

@@ -199,7 +193,7 @@ private static void ParseMediaStyleBlocks(CssData cssData, string stylesheet)
199193
while ((atrule = RegexParserUtils.GetCssAtRules(stylesheet, ref startIdx)) != null)
200194
{
201195
//Just processs @media rules
202-
if (!atrule.StartsWith("@media")) continue;
196+
if (!atrule.StartsWith("@media",StringComparison.InvariantCultureIgnoreCase)) continue;
203197

204198
//Extract specified media types
205199
MatchCollection types = RegexParserUtils.Match(RegexParserUtils.CssMediaTypes, atrule);
@@ -208,7 +202,7 @@ private static void ParseMediaStyleBlocks(CssData cssData, string stylesheet)
208202
{
209203
string line = types[0].Value;
210204

211-
if (line.StartsWith("@media") && line.EndsWith("{"))
205+
if (line.StartsWith("@media", StringComparison.InvariantCultureIgnoreCase) && line.EndsWith("{"))
212206
{
213207
//Get specified media types in the at-rule
214208
string[] media = line.Substring(6, line.Length - 7).Split(' ');
@@ -272,6 +266,7 @@ private static void FeedStyleBlock(CssData cssData, string block, string media =
272266
/// <returns>the created CSS block instance</returns>
273267
private static CssBlock ParseCssBlockImp(string className, string blockSource)
274268
{
269+
className = className.ToLower();
275270
string psedoClass = null;
276271
var colonIdx = className.IndexOf(":", StringComparison.Ordinal);
277272
if (colonIdx > -1 && !className.StartsWith("::"))
@@ -369,11 +364,13 @@ private static Dictionary<string, string> ParseCssBlockProperties(string blockSo
369364
//Extract property name and value
370365
startIdx = startIdx + (blockSource[startIdx] == ' ' ? 1 : 0);
371366
var adjEndIdx = endIdx - (blockSource[endIdx] == ' ' || blockSource[endIdx] == ';' ? 1 : 0);
372-
string propName = blockSource.Substring(startIdx, splitIdx - startIdx).Trim();
367+
string propName = blockSource.Substring(startIdx, splitIdx - startIdx).Trim().ToLower();
373368
splitIdx = splitIdx + (blockSource[splitIdx + 1] == ' ' ? 2 : 1);
374369
if (adjEndIdx >= splitIdx)
375370
{
376-
string propValue = blockSource.Substring(splitIdx, adjEndIdx - splitIdx + 1);
371+
string propValue = blockSource.Substring(splitIdx, adjEndIdx - splitIdx + 1).Trim();
372+
if(!propValue.StartsWith("url",StringComparison.InvariantCultureIgnoreCase))
373+
propValue = propValue.ToLower();
377374
AddProperty(propName, propValue, properties);
378375
}
379376
}
@@ -543,7 +540,7 @@ private static void ParseFontProperty(string propValue, Dictionary<string, strin
543540
/// <returns>parsed value</returns>
544541
private static string ParseBackgroundImageProperty(string propValue)
545542
{
546-
int startIdx = propValue.IndexOf("url(", StringComparison.Ordinal);
543+
int startIdx = propValue.IndexOf("url(", StringComparison.InvariantCultureIgnoreCase);
547544
if(startIdx > -1)
548545
{
549546
startIdx += 4;

0 commit comments

Comments
 (0)