Bug 463360 - Uneval then eval E4X with { gives error. r=jwalden
This commit is contained in:
@@ -121,6 +121,7 @@ const char js_amp_entity_str[] = "&";
|
||||
const char js_gt_entity_str[] = ">";
|
||||
const char js_lt_entity_str[] = "<";
|
||||
const char js_quot_entity_str[] = """;
|
||||
const char js_leftcurly_entity_str[] = "{";
|
||||
|
||||
#define IS_STAR(str) ((str)->length() == 1 && *(str)->chars() == '*')
|
||||
|
||||
@@ -2139,7 +2140,7 @@ AppendAttributeValue(JSContext *cx, JSCharBuffer &cb, JSString *valstr)
|
||||
* These functions mutate cb, leaving it empty.
|
||||
*/
|
||||
static JSString *
|
||||
EscapeElementValue(JSContext *cx, JSCharBuffer &cb, JSString *str)
|
||||
EscapeElementValue(JSContext *cx, JSCharBuffer &cb, JSString *str, uint32 toSourceFlag)
|
||||
{
|
||||
size_t length;
|
||||
const jschar *start;
|
||||
@@ -2160,6 +2161,17 @@ EscapeElementValue(JSContext *cx, JSCharBuffer &cb, JSString *str)
|
||||
if (!js_AppendLiteral(cb, js_amp_entity_str))
|
||||
return NULL;
|
||||
break;
|
||||
case '{':
|
||||
/*
|
||||
* If EscapeElementValue is called by toSource/uneval, we also need
|
||||
* to escape '{'. See bug 463360.
|
||||
*/
|
||||
if (toSourceFlag) {
|
||||
if (!js_AppendLiteral(cb, js_leftcurly_entity_str))
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
default:
|
||||
if (!cb.append(c))
|
||||
return NULL;
|
||||
@@ -2469,7 +2481,7 @@ XMLToXMLString(JSContext *cx, JSXML *xml, const JSXMLArray *ancestorNSes,
|
||||
} else {
|
||||
str = xml->xml_value;
|
||||
}
|
||||
return EscapeElementValue(cx, cb, str);
|
||||
return EscapeElementValue(cx, cb, str, indentLevel & TO_SOURCE_FLAG);
|
||||
|
||||
case JSXML_CLASS_ATTRIBUTE:
|
||||
/* Step 5. */
|
||||
@@ -2816,7 +2828,7 @@ ToXMLString(JSContext *cx, jsval v, uint32 toSourceFlag)
|
||||
|
||||
if (JSVAL_IS_STRING(v)) {
|
||||
JSCharBuffer cb(cx);
|
||||
return EscapeElementValue(cx, cb, JSVAL_TO_STRING(v));
|
||||
return EscapeElementValue(cx, cb, JSVAL_TO_STRING(v), toSourceFlag);
|
||||
}
|
||||
|
||||
obj = JSVAL_TO_OBJECT(v);
|
||||
@@ -2827,7 +2839,7 @@ ToXMLString(JSContext *cx, jsval v, uint32 toSourceFlag)
|
||||
if (!str)
|
||||
return NULL;
|
||||
JSCharBuffer cb(cx);
|
||||
return EscapeElementValue(cx, cb, str);
|
||||
return EscapeElementValue(cx, cb, str, toSourceFlag);
|
||||
}
|
||||
|
||||
/* Handle non-element cases in this switch, returning from each case. */
|
||||
@@ -7520,7 +7532,7 @@ JSString *
|
||||
js_EscapeElementValue(JSContext *cx, JSString *str)
|
||||
{
|
||||
JSCharBuffer cb(cx);
|
||||
return EscapeElementValue(cx, cb, str);
|
||||
return EscapeElementValue(cx, cb, str, 0);
|
||||
}
|
||||
|
||||
JSString *
|
||||
|
||||
Reference in New Issue
Block a user