mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-11 03:15:10 +00:00
Fix CSS id for string prefixed with a digit
When encoding a string as a CSS identifier, we must add an underscore if the strings starts with a digit.
This commit is contained in:
@@ -332,8 +332,7 @@ static NSCharacterSet *controlCharSet = nil;
|
||||
(cssEscapingCount + 1)
|
||||
* sizeof (unichar));
|
||||
for (count = 0; count < cssEscapingCount; count++)
|
||||
*(cssEscapingCharacters + count)
|
||||
= [[characters objectAtIndex: count] characterAtIndex: 0];
|
||||
*(cssEscapingCharacters + count) = [[characters objectAtIndex: count] characterAtIndex: 0];
|
||||
*(cssEscapingCharacters + cssEscapingCount) = 0;
|
||||
}
|
||||
|
||||
@@ -360,14 +359,20 @@ static NSCharacterSet *controlCharSet = nil;
|
||||
|
||||
cssIdentifier = [NSMutableString string];
|
||||
max = [self length];
|
||||
for (count = 0; count < max; count++)
|
||||
if (max > 0)
|
||||
{
|
||||
currentChar = [self characterAtIndex: count];
|
||||
idx = [self _cssCharacterIndex: currentChar];
|
||||
if (idx > -1)
|
||||
[cssIdentifier appendString: cssEscapingStrings[idx]];
|
||||
else
|
||||
[cssIdentifier appendFormat: @"%C", currentChar];
|
||||
if (isdigit([self characterAtIndex: 0]))
|
||||
// A CSS identifier can't start with a digit; we add an underscore
|
||||
[cssIdentifier appendString: @"_"];
|
||||
for (count = 0; count < max; count++)
|
||||
{
|
||||
currentChar = [self characterAtIndex: count];
|
||||
idx = [self _cssCharacterIndex: currentChar];
|
||||
if (idx > -1)
|
||||
[cssIdentifier appendString: cssEscapingStrings[idx]];
|
||||
else
|
||||
[cssIdentifier appendFormat: @"%C", currentChar];
|
||||
}
|
||||
}
|
||||
|
||||
return cssIdentifier;
|
||||
@@ -397,7 +402,17 @@ static NSCharacterSet *controlCharSet = nil;
|
||||
|
||||
newString = [NSMutableString string];
|
||||
max = [self length];
|
||||
for (count = 0; count < max - 2; count++)
|
||||
count = 0;
|
||||
if (max > 0
|
||||
&& [self characterAtIndex: 0] == '_'
|
||||
&& isdigit([self characterAtIndex: 1]))
|
||||
{
|
||||
/* If the identifier starts with an underscore followed by a digit,
|
||||
we remove the underscore */
|
||||
count = 1;
|
||||
}
|
||||
|
||||
for (; count < max - 2; count++)
|
||||
{
|
||||
currentChar = [self characterAtIndex: count];
|
||||
if (currentChar == '_')
|
||||
|
||||
Reference in New Issue
Block a user