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.
pull/21/merge
Francis Lachapelle 2014-03-06 21:32:36 -05:00
parent 28b1938bd9
commit 6cecca6c4f
4 changed files with 37 additions and 14 deletions

1
NEWS
View File

@ -16,6 +16,7 @@ Bug fixes
- fixed returned date format for email messages in Active Sync
- fixed missing 'name part' in address for email messages in Active Sync
- fixed race condition when syncing huge amount of deleted messages over Active Sync
- fixed encoding of string as CSS identifier when the string starts with a digit
2.2.0 (2014-02-24)
------------------

View File

@ -78,20 +78,23 @@
{
id obj;
NSArray *accounts;
NSString *key;
SOGoUser *user;
int keyCount;
key = [_key fromCSSIdentifier];
/* first check attributes directly bound to the application */
obj = [super lookupName:_key inContext:_ctx acquire:NO];
obj = [super lookupName:key inContext:_ctx acquire:NO];
if (!obj)
{
user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
accounts = [user mailAccounts];
keyCount = [_key intValue];
if ([_key isEqualToString: [NSString stringWithFormat: @"%d", keyCount]]
keyCount = [key intValue];
if ([key isEqualToString: [NSString stringWithFormat: @"%d", keyCount]]
&& keyCount > -1 && keyCount < [accounts count])
obj = [SOGoMailAccount objectWithName: _key inContainer: self];
obj = [SOGoMailAccount objectWithName: key inContainer: self];
else
obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
}

View File

@ -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 == '_')

View File

@ -106,6 +106,10 @@ String.prototype.asCSSIdentifier = function() {
newString = newString.replace(re, escapeds[i]);
}
if (/^\d+/.test(newString)) {
newString = '_' + newString;
}
return newString;
};