Changed decimal escape handling to backward compatible rather than ECMA3

conforming. (Bug#158159)
This commit is contained in:
rogerl%netscape.com 2002-07-23 21:38:03 +00:00
Родитель 1845468c5d
Коммит c437701852
1 изменённых файлов: 51 добавлений и 68 удалений

Просмотреть файл

@ -789,9 +789,47 @@ System.out.println();
return true; return true;
/* Decimal escape */ /* Decimal escape */
case '0': case '0':
if (state.cx.getLanguageVersion() != Context.VERSION_DEFAULT && /*
state.cx.getLanguageVersion() <= Context.VERSION_1_4) { * Under 'strict' ECMA 3, we interpret \0 as NUL and don't accept octal.
/* octal escape */ * However, (XXX and since Rhino doesn't have a 'strict' mode) we'll just
* behave the old way for compatibility reasons.
* (see http://bugzilla.mozilla.org/show_bug.cgi?id=141078)
*
*/
/* octal escape */
num = 0;
while (state.cp < state.cpend) {
c = src[state.cp];
if ((c >= '0') && (c <= '7')) {
state.cp++;
tmp = 8 * num + (c - '0');
if (tmp > 0377)
break;
num = tmp;
}
else
break;
}
c = (char)(num);
doFlat(state, c);
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
termStart = state.cp - 1;
num = getDecimalValue(c, state);
/*
* n > 9 and > count of parentheses,
* then treat as octal instead.
*/
if ((num > 9) && (num > state.parenCount)) {
state.cp = termStart;
num = 0; num = 0;
while (state.cp < state.cpend) { while (state.cp < state.cpend) {
c = src[state.cp]; c = src[state.cp];
@ -806,71 +844,15 @@ System.out.println();
break; break;
} }
c = (char)(num); c = (char)(num);
doFlat(state, c);
break;
} }
else /* otherwise, it's a back-reference */
c = 0; state.result = new RENode(REOP_BACKREF);
doFlat(state, c); if (state.result == null)
break; return false;
case '1': state.result.parenIndex = num - 1;
case '2': state.progLength += 3;
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
termStart = state.cp - 1;
num = getDecimalValue(c, state);
if (state.cx.getLanguageVersion() != Context.VERSION_DEFAULT &&
state.cx.getLanguageVersion() <= Context.VERSION_1_4) {
/*
* n in [8-9] and > count of parentheses,
* then revert to '8' or '9', ignoring the '\'
*/
if (((num == 8) || (num == 9))
&& (num > state.parenCount)) {
c = (char)(num + '0');
doFlat(state, c);
break;
}
/*
* more than 1 digit, or a number greater than
* the count of parentheses => it's an octal
*/
if (((state.cp - termStart) > 1)
|| (num > state.parenCount)) {
state.cp = termStart;
num = 0;
while (state.cp < state.cpend) {
c = src[state.cp];
if ((c >= '0') && (c <= '7')) {
state.cp++;
tmp = 8 * num + (c - '0');
if (tmp > 0377)
break;
num = tmp;
}
else
break;
}
c = (char)(num);
doFlat(state, c);
break;
}
state.result = new RENode(REOP_BACKREF);
if (state.result == null)
return false;
state.result.parenIndex = num - 1;
state.progLength += 3;
}
else {
state.result = new RENode(REOP_BACKREF);
if (state.result == null)
return false;
state.result.parenIndex = num - 1;
state.progLength += 3;
}
break; break;
/* Control escape */ /* Control escape */
case 'f': case 'f':
@ -982,7 +964,8 @@ System.out.println();
{ {
RENode result = null; RENode result = null;
termStart = state.cp; termStart = state.cp;
if ((src[state.cp] == '?') if ((state.cp < state.cpend)
&& (src[state.cp] == '?')
&& ( (src[state.cp + 1] == '=') && ( (src[state.cp + 1] == '=')
|| (src[state.cp + 1] == '!') || (src[state.cp + 1] == '!')
|| (src[state.cp + 1] == ':') )) { || (src[state.cp + 1] == ':') )) {