diff options
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | src/xine-utils/xmllexer.c | 25 |
2 files changed, 24 insertions, 3 deletions
@@ -10,6 +10,8 @@ xine-lib (1.1.9) (unreleased) * Fixed handling of streamed Flash videos (broken in 1.1.5). * Fixed division by zero in sputext decoder * Build fix for when using Linux 2.6.23 headers. [Bug 1820958] + * Implemented decoding of XML character entities with codes >= 256. + This requires conversion to UTF-8 of entities with codes >= 128. xine-lib (1.1.8) * Send a channel-changed event to the frontend when receiving the SYNC diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index 754a006f9..068988eaa 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -39,6 +39,9 @@ #include <ctype.h> #include <string.h> #include <stdlib.h> +#ifdef HAVE_ICONV +#include <iconv.h> +#endif /* private constants*/ #define NORMAL 0 /* normal lex mode */ @@ -463,7 +466,7 @@ char *lexer_decode_entities (const char *tok) { /* parse the character entity (on failure, treat it as literal text) */ const char *tp = tok; - long i; + signed long i; for (i = 0; lexer_entities[i].code; ++i) if (!strncmp (lexer_entities[i].name, tok, lexer_entities[i].namelen) @@ -491,7 +494,7 @@ char *lexer_decode_entities (const char *tok) else i = strtol (tp, (char **)&tp, 10); - if (i < 1 || i > 255 || *tp != ';') + if (*tp != ';' || i < 1) { /* out of range, or format error */ *bp++ = '&'; @@ -499,7 +502,23 @@ char *lexer_decode_entities (const char *tok) } tok = tp + 1; - *bp++ = i; + + if (i < 128) + /* ASCII - store as-is */ + *bp++ = i; + else + { + /* Non-ASCII, so convert to UTF-8 */ + int count = (i >= 0x04000000) ? 5 : + (i >= 0x00200000) ? 4 : + (i >= 0x00010000) ? 3 : + (i >= 0x00000800) ? 2 : 1; + *bp = (char)(0x1F80 >> count); + count *= 6; + *bp++ |= i >> count; + while ((count -= 6) >= 0) + *bp++ = 128 | ((i >> count) & 0x3F); + } } } *bp = 0; |