From 0982d50643eb8e46fc6cb54d17616375cc08198e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Vall=C3=A9s?= Date: Thu, 10 Sep 2015 10:24:50 +0200 Subject: [PATCH] Improve first character check in CSS identifiers A CSS identifier can't start with a digit, so when a folder name does, a '_' character is appended at the beginning of its CSS identifier. The check for this first character used the `isdigit()` function, which takes a `char` argument, while `[self objectAtIndex: 0]` returns a `unichar`, i.e. a 16-bit unsigned integer. This caused some non-digit characters to pass this check (e.g. Chinese characters), ending up with an underscore at the beginning of the folder name. --- SoObjects/SOGo/NSString+Utilities.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index d7d85e5f5..3895cd923 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -373,6 +373,7 @@ static int cssEscapingCount; - (NSString *) asCSSIdentifier { + NSCharacterSet *numericSet; NSMutableString *cssIdentifier; unichar currentChar; int count, max, idx; @@ -381,10 +382,12 @@ static int cssEscapingCount; [self _setupCSSEscaping]; cssIdentifier = [NSMutableString string]; + numericSet = [NSCharacterSet decimalDigitCharacterSet]; max = [self length]; + if (max > 0) { - if (isdigit([self characterAtIndex: 0])) + if ([numericSet characterIsMember: [self characterAtIndex: 0]]) // A CSS identifier can't start with a digit; we add an underscore [cssIdentifier appendString: @"_"]; for (count = 0; count < max; count++) @@ -415,6 +418,7 @@ static int cssEscapingCount; - (NSString *) fromCSSIdentifier { + NSCharacterSet *numericSet; NSMutableString *newString; NSString *currentString; int count, length, max, idx; @@ -423,12 +427,14 @@ static int cssEscapingCount; if (!cssEscapingStrings) [self _setupCSSEscaping]; + numericSet = [NSCharacterSet decimalDigitCharacterSet]; newString = [NSMutableString string]; max = [self length]; count = 0; + if (max > 0 && [self characterAtIndex: 0] == '_' - && isdigit([self characterAtIndex: 1])) + && [numericSet characterIsMember: [self characterAtIndex: 1]]) { /* If the identifier starts with an underscore followed by a digit, we remove the underscore */