Skip to content

Commit

Permalink
* fix case-senssitive url in css not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHub committed Mar 7, 2014
1 parent 4c2ed79 commit db9e1a1
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions Source/HtmlRenderer/Parse/CssParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ public static void ParseStyleSheet(CssData cssData, string stylesheet)
{
if (!String.IsNullOrEmpty(stylesheet))
{
// Convert everything to lower-case so not to handle case in code
stylesheet = stylesheet.ToLower();

stylesheet = RemoveStylesheetComments(stylesheet);

ParseStyleBlocks(cssData, stylesheet);
Expand All @@ -85,9 +82,6 @@ public static void ParseStyleSheet(CssData cssData, string stylesheet)
/// <returns>the created CSS block instance</returns>
public static CssBlock ParseCssBlock(string className, string blockSource)
{
// Convert everything to lower-case so not to handle case in code
blockSource = blockSource.ToLower();

return ParseCssBlockImp(className, blockSource);
}

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

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

if (line.StartsWith("@media") && line.EndsWith("{"))
if (line.StartsWith("@media", StringComparison.InvariantCultureIgnoreCase) && line.EndsWith("{"))
{
//Get specified media types in the at-rule
string[] media = line.Substring(6, line.Length - 7).Split(' ');
Expand Down Expand Up @@ -272,6 +266,7 @@ private static void FeedStyleBlock(CssData cssData, string block, string media =
/// <returns>the created CSS block instance</returns>
private static CssBlock ParseCssBlockImp(string className, string blockSource)
{
className = className.ToLower();
string psedoClass = null;
var colonIdx = className.IndexOf(":", StringComparison.Ordinal);
if (colonIdx > -1 && !className.StartsWith("::"))
Expand Down Expand Up @@ -369,11 +364,13 @@ private static Dictionary<string, string> ParseCssBlockProperties(string blockSo
//Extract property name and value
startIdx = startIdx + (blockSource[startIdx] == ' ' ? 1 : 0);
var adjEndIdx = endIdx - (blockSource[endIdx] == ' ' || blockSource[endIdx] == ';' ? 1 : 0);
string propName = blockSource.Substring(startIdx, splitIdx - startIdx).Trim();
string propName = blockSource.Substring(startIdx, splitIdx - startIdx).Trim().ToLower();
splitIdx = splitIdx + (blockSource[splitIdx + 1] == ' ' ? 2 : 1);
if (adjEndIdx >= splitIdx)
{
string propValue = blockSource.Substring(splitIdx, adjEndIdx - splitIdx + 1);
string propValue = blockSource.Substring(splitIdx, adjEndIdx - splitIdx + 1).Trim();
if(!propValue.StartsWith("url",StringComparison.InvariantCultureIgnoreCase))
propValue = propValue.ToLower();
AddProperty(propName, propValue, properties);
}
}
Expand Down Expand Up @@ -543,7 +540,7 @@ private static void ParseFontProperty(string propValue, Dictionary<string, strin
/// <returns>parsed value</returns>
private static string ParseBackgroundImageProperty(string propValue)
{
int startIdx = propValue.IndexOf("url(", StringComparison.Ordinal);
int startIdx = propValue.IndexOf("url(", StringComparison.InvariantCultureIgnoreCase);
if(startIdx > -1)
{
startIdx += 4;
Expand Down

0 comments on commit db9e1a1

Please sign in to comment.