diff --git a/Core/Source/DTHTMLElement.m b/Core/Source/DTHTMLElement.m index f0747e4e2..13cd7b85f 100644 --- a/Core/Source/DTHTMLElement.m +++ b/Core/Source/DTHTMLElement.m @@ -273,7 +273,7 @@ - (void)applyStyleDictionary:(NSDictionary *)styles _styles = styles; // register pseudo-selector contents - self.beforeContent = [_styles objectForKey:@"before:content"]; + self.beforeContent = [[_styles objectForKey:@"before:content"] stringByDecodingCSSContentAttribute]; NSString *fontSize = [styles objectForKey:@"font-size"]; if (fontSize) diff --git a/Core/Source/NSString+CSS.h b/Core/Source/NSString+CSS.h index 672e22c94..a346f7a70 100755 --- a/Core/Source/NSString+CSS.h +++ b/Core/Source/NSString+CSS.h @@ -43,4 +43,9 @@ */ - (CGFloat)CSSpixelSize; +/** + Decodes a content attribute which might contained unicode sequences. + */ +- (NSString *)stringByDecodingCSSContentAttribute; + @end \ No newline at end of file diff --git a/Core/Source/NSString+CSS.m b/Core/Source/NSString+CSS.m index a2203c480..c38a9b057 100644 --- a/Core/Source/NSString+CSS.m +++ b/Core/Source/NSString+CSS.m @@ -223,4 +223,99 @@ - (CGFloat)CSSpixelSize return [self floatValue]; } +- (NSString *)stringByDecodingCSSContentAttribute +{ + NSUInteger length = [self length]; + + unichar *characters = calloc(length, sizeof(unichar)); + unichar *final = calloc(length, sizeof(unichar)); + + [self getCharacters:characters range:NSMakeRange(0, length)]; + + NSUInteger outChars = 0; + + BOOL inEscapedSequence = NO; + unichar decodedChar = 0; + NSUInteger escapedCharacterCount = 0; + + for (NSUInteger idx=0; idx='0' && character<='9') || (character>='A' && character<='F') || (character>='a' && character<='f')) + { + // hex digit + decodedChar *= 16; + + if (character>='0' && character<='9') + { + decodedChar += (character - '0'); + } + else if (character>='A' && character<='F') + { + decodedChar += (character - 'A' + 10); + } + else if (character>='a' && character<='f') + { + decodedChar += (character - 'a' + 10); + } + + escapedCharacterCount++; + } + else + { + // illegal character following slash + final[outChars++] = '\\'; + final[outChars++] = character; + + inEscapedSequence = NO; + } + } + else + { + if (character == '\\') + { + // begin of escape sequence + decodedChar = 0; + escapedCharacterCount = 0; + inEscapedSequence = YES; + } + else + { + if (inEscapedSequence) + { + // output what we have decoded so far + final[outChars++] = decodedChar; + } + + inEscapedSequence = NO; + + // just copy + final[outChars++] = character; + } + } + } + + // if string ended in escaped sequence we still need to output + if (inEscapedSequence) + { + // output what we have decoded so far + final[outChars++] = decodedChar; + } + + free(characters); + NSString *clean = [[NSString alloc] initWithCharacters:final length:outChars]; + free(final); + + return clean; +} + @end