From f34cecbae27a484f1aa026840dc6d224ffa0b65d Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Fri, 8 Nov 2019 21:26:08 +0100 Subject: [PATCH] jscript: Treat only ASCII digits as digits. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/jscript/array.c | 4 ++-- dlls/jscript/dispex.c | 2 +- dlls/jscript/global.c | 18 ++++++++++-------- dlls/jscript/jscript.h | 5 +++++ dlls/jscript/json.c | 2 +- dlls/jscript/jsutils.c | 6 +++--- dlls/jscript/lex.c | 30 +++++++++++++++--------------- dlls/jscript/string.c | 4 ++-- dlls/jscript/tests/api.js | 1 + 9 files changed, 40 insertions(+), 32 deletions(-) diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c index 494010df429..51a4cf1d38d 100644 --- a/dlls/jscript/array.c +++ b/dlls/jscript/array.c @@ -1191,10 +1191,10 @@ static void Array_on_put(jsdisp_t *dispex, const WCHAR *name) const WCHAR *ptr = name; DWORD id = 0; - if(!iswdigit(*ptr)) + if(!is_digit(*ptr)) return; - while(*ptr && iswdigit(*ptr)) { + while(*ptr && is_digit(*ptr)) { id = id*10 + (*ptr-'0'); ptr++; } diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c index 3c2733086b7..463fd2fb481 100644 --- a/dlls/jscript/dispex.c +++ b/dlls/jscript/dispex.c @@ -239,7 +239,7 @@ static HRESULT find_prop_name(jsdisp_t *This, unsigned hash, const WCHAR *name, const WCHAR *ptr; unsigned idx = 0; - for(ptr = name; iswdigit(*ptr) && idx < 0x10000; ptr++) + for(ptr = name; is_digit(*ptr) && idx < 0x10000; ptr++) idx = idx*10 + (*ptr-'0'); if(!*ptr && idx < This->builtin_info->idx_length(This)) { prop = alloc_prop(This, name, PROP_IDX, This->builtin_info->idx_put ? PROPF_WRITABLE : 0); diff --git a/dlls/jscript/global.c b/dlls/jscript/global.c index 33e641530eb..37b222beba1 100644 --- a/dlls/jscript/global.c +++ b/dlls/jscript/global.c @@ -376,6 +376,8 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag return S_OK; } + TRACE("%s\n", debugstr_jsval(argv[0])); + hres = to_flat_string(ctx, argv[0], &val_str, &str); if(FAILED(hres)) return hres; @@ -389,10 +391,10 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag str++; } - if(iswdigit(*str)) + if(is_digit(*str)) ret_nan = FALSE; - while(iswdigit(*str)) { + while(is_digit(*str)) { hlp = d*10 + *(str++) - '0'; if(d>MAXLONGLONG/10 || hlp<0) { exp++; @@ -401,17 +403,17 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag else d = hlp; } - while(iswdigit(*str)) { + while(is_digit(*str)) { exp++; str++; } if(*str == '.') str++; - if(iswdigit(*str)) + if(is_digit(*str)) ret_nan = FALSE; - while(iswdigit(*str)) { + while(is_digit(*str)) { hlp = d*10 + *(str++) - '0'; if(d>MAXLONGLONG/10 || hlp<0) break; @@ -419,7 +421,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag d = hlp; exp--; } - while(iswdigit(*str)) + while(is_digit(*str)) str++; if(*str && !ret_nan && (*str=='e' || *str=='E')) { @@ -433,7 +435,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag str++; } - while(iswdigit(*str)) { + while(is_digit(*str)) { if(e>INT_MAX/10 || (e = e*10 + *str++ - '0')<0) e = INT_MAX; } @@ -461,7 +463,7 @@ static HRESULT JSGlobal_parseFloat(script_ctx_t *ctx, vdisp_t *jsthis, WORD flag static inline int hex_to_int(const WCHAR wch) { if(towupper(wch)>='A' && towupper(wch)<='F') return towupper(wch)-'A'+10; - if(iswdigit(wch)) return wch-'0'; + if(is_digit(wch)) return wch-'0'; return -1; } diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 2dd73d61699..5d635b7f41f 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -354,6 +354,11 @@ HRESULT decode_source(WCHAR*) DECLSPEC_HIDDEN; HRESULT double_to_string(double,jsstr_t**) DECLSPEC_HIDDEN; BOOL is_finite(double) DECLSPEC_HIDDEN; +static inline BOOL is_digit(WCHAR c) +{ + return '0' <= c && c <= '9'; +} + typedef struct named_item_t { IDispatch *disp; DWORD flags; diff --git a/dlls/jscript/json.c b/dlls/jscript/json.c index ade72c9184e..3c198de3c2c 100644 --- a/dlls/jscript/json.c +++ b/dlls/jscript/json.c @@ -260,7 +260,7 @@ static HRESULT parse_json_value(json_parse_ctx_t *ctx, jsval_t *r) skip_spaces(ctx); } - if(*ctx->ptr == '0' && ctx->ptr + 1 < ctx->end && iswdigit(ctx->ptr[1])) + if(*ctx->ptr == '0' && ctx->ptr + 1 < ctx->end && is_digit(ctx->ptr[1])) break; hres = parse_decimal(&ctx->ptr, ctx->end, &n); diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index bb35ed7df54..0702c4e0bea 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -555,7 +555,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret) return S_OK; } - while(iswdigit(*ptr)) + while(is_digit(*ptr)) d = d*10 + (*ptr++ - '0'); if(*ptr == 'e' || *ptr == 'E') { @@ -570,7 +570,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret) ptr++; } - while(iswdigit(*ptr)) + while(is_digit(*ptr)) l = l*10 + (*ptr++ - '0'); if(eneg) l = -l; @@ -580,7 +580,7 @@ static HRESULT str_to_number(jsstr_t *str, double *ret) DOUBLE dec = 0.1; ptr++; - while(iswdigit(*ptr)) { + while(is_digit(*ptr)) { d += dec * (*ptr++ - '0'); dec *= 0.1; } diff --git a/dlls/jscript/lex.c b/dlls/jscript/lex.c index 4f0ea45362e..1b34a14a792 100644 --- a/dlls/jscript/lex.c +++ b/dlls/jscript/lex.c @@ -297,11 +297,11 @@ BOOL unescape(WCHAR *str, size_t *len) c += i; break; default: - if(iswdigit(*p)) { + if(is_digit(*p)) { c = *p++ - '0'; - if(p < end && iswdigit(*p)) { + if(p < end && is_digit(*p)) { c = c*8 + (*p++ - '0'); - if(p < end && iswdigit(*p)) + if(p < end && is_digit(*p)) c = c*8 + (*p++ - '0'); } p--; @@ -400,7 +400,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) LONGLONG d = 0, hlp; int exp = 0; - while(ptr < end && iswdigit(*ptr)) { + while(ptr < end && is_digit(*ptr)) { hlp = d*10 + *(ptr++) - '0'; if(d>MAXLONGLONG/10 || hlp<0) { exp++; @@ -409,7 +409,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) else d = hlp; } - while(ptr < end && iswdigit(*ptr)) { + while(ptr < end && is_digit(*ptr)) { exp++; ptr++; } @@ -417,7 +417,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) if(*ptr == '.') { ptr++; - while(ptr < end && iswdigit(*ptr)) { + while(ptr < end && is_digit(*ptr)) { hlp = d*10 + *(ptr++) - '0'; if(d>MAXLONGLONG/10 || hlp<0) break; @@ -425,7 +425,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) d = hlp; exp--; } - while(ptr < end && iswdigit(*ptr)) + while(ptr < end && is_digit(*ptr)) ptr++; } @@ -438,7 +438,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) }else if(*ptr == '-') { sign = -1; ptr++; - }else if(!iswdigit(*ptr)) { + }else if(!is_digit(*ptr)) { WARN("Expected exponent part\n"); return E_FAIL; } @@ -449,7 +449,7 @@ HRESULT parse_decimal(const WCHAR **iter, const WCHAR *end, double *ret) return E_FAIL; } - while(ptr < end && iswdigit(*ptr)) { + while(ptr < end && is_digit(*ptr)) { if(e > INT_MAX/10 || (e = e*10 + *ptr++ - '0')<0) e = INT_MAX; } @@ -500,12 +500,12 @@ static BOOL parse_numeric_literal(parser_ctx_t *ctx, double *ret) return TRUE; } - if(iswdigit(*ctx->ptr)) { + if(is_digit(*ctx->ptr)) { unsigned base = 8; const WCHAR *ptr; double val = 0; - for(ptr = ctx->ptr; ptr < ctx->end && iswdigit(*ptr); ptr++) { + for(ptr = ctx->ptr; ptr < ctx->end && is_digit(*ptr); ptr++) { if(*ptr > '7') { base = 10; break; @@ -514,7 +514,7 @@ static BOOL parse_numeric_literal(parser_ctx_t *ctx, double *ret) do { val = val*base + *ctx->ptr-'0'; - }while(++ctx->ptr < ctx->end && iswdigit(*ctx->ptr)); + }while(++ctx->ptr < ctx->end && is_digit(*ctx->ptr)); /* FIXME: Do we need it here? */ if(ctx->ptr < ctx->end && (is_identifier_char(*ctx->ptr) || *ctx->ptr == '.')) { @@ -564,7 +564,7 @@ static int next_token(parser_ctx_t *ctx, void *lval) return parse_identifier(ctx, lval); } - if(iswdigit(*ctx->ptr)) { + if(is_digit(*ctx->ptr)) { double n; if(!parse_numeric_literal(ctx, &n)) @@ -591,7 +591,7 @@ static int next_token(parser_ctx_t *ctx, void *lval) return '}'; case '.': - if(ctx->ptr+1 < ctx->end && iswdigit(ctx->ptr[1])) { + if(ctx->ptr+1 < ctx->end && is_digit(ctx->ptr[1])) { double n; HRESULT hres; hres = parse_decimal(&ctx->ptr, ctx->end, &n); @@ -909,7 +909,7 @@ int try_parse_ccval(parser_ctx_t *ctx, ccval_t *r) if(!skip_spaces(ctx)) return -1; - if(iswdigit(*ctx->ptr)) { + if(is_digit(*ctx->ptr)) { double n; if(!parse_numeric_literal(ctx, &n)) diff --git a/dlls/jscript/string.c b/dlls/jscript/string.c index 2643c57581d..7c8fc36934a 100644 --- a/dlls/jscript/string.c +++ b/dlls/jscript/string.c @@ -904,14 +904,14 @@ static HRESULT String_replace(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, un default: { DWORD idx; - if(!iswdigit(ptr2[1])) { + if(!is_digit(ptr2[1])) { hres = strbuf_append(&ret, ptr2, 1); ptr = ptr2+1; break; } idx = ptr2[1] - '0'; - if(iswdigit(ptr2[2]) && idx*10 + (ptr2[2]-'0') <= match->paren_count) { + if(is_digit(ptr2[2]) && idx*10 + (ptr2[2]-'0') <= match->paren_count) { idx = idx*10 + (ptr[2]-'0'); ptr = ptr2+3; }else if(idx && idx <= match->paren_count) { diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index d62a6434710..1a81253a02a 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -1442,6 +1442,7 @@ ok(isNaN(parseFloat('not a number')), "parseFloat('not a number') is not NaN"); ok(parseFloat('+13.2e-3') === 13.2e-3, "parseFloat('+13.2e-3') = " + parseFloat('+13.2e-3')); ok(parseFloat('.12') === 0.12, "parseFloat('.12') = " + parseFloat('.12')); ok(parseFloat('1e') === 1, "parseFloat('1e') = " + parseFloat('1e')); +ok(isNaN(parseFloat('\uff16')), "parseFloat('\\uD835') is not NaN"); tmp = Math.min(1); ok(tmp === 1, "Math.min(1) = " + tmp);