From: Fabrice Bellard Date: Tue, 10 Nov 2026 10:16:24 +0000 (+0100) Subject: moved OOB in Intl.NumberFormat (#610 point 4) X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=3cbe3f2fea7c14c1e57c434346b491418159b9a9;p=quickjs.git moved OOB in Intl.NumberFormat (#610 point 4) --- diff --git a/intl/numberformat.c b/intl/numberformat.c index 60ef2f1..8efe89f 100644 --- a/intl/numberformat.c +++ b/intl/numberformat.c @@ -2425,9 +2425,13 @@ static JSValue intl_mv_format_scientific(JSContext *ctx, IntlMV *mv, JSNumberFor /* Integer part of mantissa */ { char *int_buf = js_malloc(ctx, (size_t)digits_before + 1); + int n; if (!int_buf) goto sci_fail; - memcpy(int_buf, mv->digits, (size_t)digits_before); - int_buf[digits_before] = '\0'; + n = min_int(digits_before, mv->num_digits); + memcpy(int_buf, mv->digits, n); + while (n < digits_before) + int_buf[n++] = '0'; + int_buf[n] = '\0'; dbuf_putstr(&db, int_buf); if (!JS_IsUndefined(parts)) nf_add_part(ctx, parts, "integer", int_buf); diff --git a/tests/test_intl.js b/tests/test_intl.js index 4b3b81b..b881fe9 100644 --- a/tests/test_intl.js +++ b/tests/test_intl.js @@ -224,7 +224,8 @@ function test_numberFormat() { assert(new Intl.NumberFormat('en', { style: 'percent' }).format(0.5), "50%", "en percent"); assert(new Intl.NumberFormat('en', { style: 'currency', currency: 'EUR' }).format(1234.56), "€1,234.56", "en EUR currency"); - + assert(new Intl.NumberFormat("en", { notation: "engineering" }).format(1e23), "100E21"); + // de assert(new Intl.NumberFormat('de').format(1234567.89), "1.234.567,89", "de number"); assert(new Intl.NumberFormat('de').format(1000000), "1.000.000", "de grouping");