Correctly parse octal escapes for plist strings.

It seems the code expected octal escapes to always start with 0. This is
not the case. Also, octal escapes are limited to 3 digits (and hex to 2).

This fixes the garbled bold text in ITS.
This commit is contained in:
Bill Currie 2013-01-08 16:54:23 +09:00
parent febb615580
commit a4714ac9b5

View file

@ -526,7 +526,7 @@ PL_ParseQuotedString (pldata_t *pl)
char c = pl->ptr[pl->pos];
if (escaped) {
if (escaped == 1 && c == '0') {
if (escaped == 1 && inrange (c, '0', '7')) {
escaped++;
hex = false;
} else if (escaped > 1) {
@ -534,10 +534,11 @@ PL_ParseQuotedString (pldata_t *pl)
hex = true;
shrink++;
escaped++;
} else if (hex && isxdigit ((byte) c)) {
} else if (hex && inrange (escaped, 3, 4)
&& isxdigit ((byte) c)) {
shrink++;
escaped++;
} else if (c >= '0' && c <= '7') {
} else if (inrange (escaped, 1, 3) && inrange (c, '0', '7')) {
shrink++;
escaped++;
} else {
@ -585,19 +586,21 @@ PL_ParseQuotedString (pldata_t *pl)
char c = pl->ptr[j];
if (escaped) {
if (escaped == 1 && c == '0') {
chars[k] = 0;
if (escaped == 1 && inrange (c, '0', '7')) {
chars[k] = c - '0';
hex = false;
escaped++;
} else if (escaped > 1) {
if (escaped == 2 && c == 'x') {
hex = true;
escaped++;
} else if (hex && isxdigit ((byte) c)) {
} else if (hex && inrange (escaped, 3, 4)
&& isxdigit ((byte) c)) {
chars[k] <<= 4;
chars[k] |= char2num (c);
escaped++;
} else if (inrange (c, '0', '7')) {
} else if (inrange (escaped, 1, 3)
&& inrange (c, '0', '7')) {
chars[k] <<= 3;
chars[k] |= (c - '0');
escaped++;