Bug 352437 - Part c: Escape quotes in tagify; r=jorendorff

This commit is contained in:
Ms2ger 2012-08-04 09:29:35 +02:00
parent 468ea070bf
commit f9da755325

View File

@ -2931,8 +2931,13 @@ tagify(JSContext *cx, const char *begin, JSLinearString *param, const char *end,
size_t beglen = strlen(begin); size_t beglen = strlen(begin);
size_t taglen = 1 + beglen + 1; /* '<begin' + '>' */ size_t taglen = 1 + beglen + 1; /* '<begin' + '>' */
if (param) { if (param) {
size_t parlen = param->length(); size_t numChars = param->length();
taglen += 2 + parlen + 1; /* '="param"' */ const jschar *parchars = param->chars();
for (size_t i = 0, parlen = numChars; i < parlen; ++i) {
if (parchars[i] == '"')
numChars += 5; /* len(&quot;) - len(") */
}
taglen += 2 + numChars + 1; /* '="param"' */
} }
size_t endlen = strlen(end); size_t endlen = strlen(end);
taglen += str->length() + 2 + endlen + 1; /* 'str</end>' */ taglen += str->length() + 2 + endlen + 1; /* 'str</end>' */
@ -2949,7 +2954,14 @@ tagify(JSContext *cx, const char *begin, JSLinearString *param, const char *end,
if (param) { if (param) {
sb.infallibleAppend('='); sb.infallibleAppend('=');
sb.infallibleAppend('"'); sb.infallibleAppend('"');
MOZ_ALWAYS_TRUE(sb.append(param)); const jschar *parchars = param->chars();
for (size_t i = 0, parlen = param->length(); i < parlen; ++i) {
if (parchars[i] != '"') {
sb.infallibleAppend(parchars[i]);
} else {
MOZ_ALWAYS_TRUE(sb.append("&quot;"));
}
}
sb.infallibleAppend('"'); sb.infallibleAppend('"');
} }