зеркало из https://github.com/mozilla/pjs.git
Fix to 47409 -
Don't use timezone comment in javascript Date object toString string if it looks like it might not be ASCII. a,r=beard
This commit is contained in:
Родитель
16bad1d0a3
Коммит
3ef2f70f03
|
@ -1497,6 +1497,8 @@ date_format(JSContext *cx, jsdouble date, jsval *rval)
|
||||||
char buf[100];
|
char buf[100];
|
||||||
JSString *str;
|
JSString *str;
|
||||||
char tzbuf[100];
|
char tzbuf[100];
|
||||||
|
JSBool usetz;
|
||||||
|
uintN i, tzlen;
|
||||||
PRMJTime split;
|
PRMJTime split;
|
||||||
|
|
||||||
if (!JSDOUBLE_IS_FINITE(date)) {
|
if (!JSDOUBLE_IS_FINITE(date)) {
|
||||||
|
@ -1526,6 +1528,29 @@ date_format(JSContext *cx, jsdouble date, jsval *rval)
|
||||||
new_explode(date, &split, JS_TRUE);
|
new_explode(date, &split, JS_TRUE);
|
||||||
PRMJ_FormatTime(tzbuf, sizeof tzbuf, "(%Z) ", &split);
|
PRMJ_FormatTime(tzbuf, sizeof tzbuf, "(%Z) ", &split);
|
||||||
|
|
||||||
|
/* Decide whether to use the resulting timezone string.
|
||||||
|
*
|
||||||
|
* Reject it if it contains any non-ASCII, non-alphanumeric characters.
|
||||||
|
* It's then likely in some other character encoding, and we probably
|
||||||
|
* won't display it correctly.
|
||||||
|
*/
|
||||||
|
usetz = JS_TRUE;
|
||||||
|
tzlen = strlen(tzbuf);
|
||||||
|
if (tzlen > 100) {
|
||||||
|
usetz = JS_FALSE;
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < tzlen; i++) {
|
||||||
|
jschar c = tzbuf[i];
|
||||||
|
if (c > 127 || !(isalpha(c) || isdigit(c) ||
|
||||||
|
c == ' ' || c == '(' || c == ')'))
|
||||||
|
usetz = JS_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Also reject it if it's not parenthesized or if it's '()'. */
|
||||||
|
if (tzbuf[0] != '(' || tzbuf[1] == ')')
|
||||||
|
usetz = JS_FALSE;
|
||||||
|
|
||||||
/* Avoid dependence on PRMJ_FormatTimeUSEnglish, because it
|
/* Avoid dependence on PRMJ_FormatTimeUSEnglish, because it
|
||||||
* requires a PRMJTime... which only has 16-bit years. Sub-ECMA.
|
* requires a PRMJTime... which only has 16-bit years. Sub-ECMA.
|
||||||
*/
|
*/
|
||||||
|
@ -1537,12 +1562,7 @@ date_format(JSContext *cx, jsdouble date, jsval *rval)
|
||||||
MinFromTime(local),
|
MinFromTime(local),
|
||||||
SecFromTime(local),
|
SecFromTime(local),
|
||||||
offset,
|
offset,
|
||||||
|
usetz ? tzbuf : "",
|
||||||
/* don't print anything for the TZA comment if we got '()'
|
|
||||||
* or something non-parenthesized from the OS.
|
|
||||||
*/
|
|
||||||
((tzbuf[0] == '(' && tzbuf[1] != ')') ? tzbuf : ""),
|
|
||||||
|
|
||||||
YearFromTime(local));
|
YearFromTime(local));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче