From 66ba778cadcc092b390cd867ac05c7b55c1f7968 Mon Sep 17 00:00:00 2001 From: Qian Hong Date: Thu, 2 Oct 2014 14:09:10 +0800 Subject: [PATCH] jscript: Ignore BOM mark in next_token. --- dlls/jscript/lex.c | 2 +- dlls/jscript/tests/run.c | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/dlls/jscript/lex.c b/dlls/jscript/lex.c index b4a37005764..af4b24b2b90 100644 --- a/dlls/jscript/lex.c +++ b/dlls/jscript/lex.c @@ -241,7 +241,7 @@ static BOOL skip_comment(parser_ctx_t *ctx) static BOOL skip_spaces(parser_ctx_t *ctx) { - while(ctx->ptr < ctx->end && isspaceW(*ctx->ptr)) { + while(ctx->ptr < ctx->end && (isspaceW(*ctx->ptr) || *ctx->ptr == 0xFEFF /* UTF16 BOM */)) { if(is_endline(*ctx->ptr++)) ctx->nl = TRUE; } diff --git a/dlls/jscript/tests/run.c b/dlls/jscript/tests/run.c index aa1783e0599..452f8109154 100644 --- a/dlls/jscript/tests/run.c +++ b/dlls/jscript/tests/run.c @@ -144,6 +144,7 @@ DEFINE_EXPECT(DeleteMemberByDispID_false); #define DISPID_TESTOBJ_ONLYDISPID 0x2001 #define DISPID_TESTOBJ_WITHPROP 0x2002 +#define JS_E_OUT_OF_MEMORY 0x800a03ec #define JS_E_INVALID_CHAR 0x800a03f6 static const WCHAR testW[] = {'t','e','s','t',0}; @@ -1966,6 +1967,56 @@ static void test_script_exprs(void) testing_expr = FALSE; } +struct bom_test +{ + WCHAR str[1024]; + HRESULT hres; +}; + +static void run_bom_tests(void) +{ + BSTR src; + int i; + HRESULT hres; + struct bom_test bom_tests[] = { + {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK}, + {{0xFEFF,'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK}, + {{'v',0xFEFF,'a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, JS_E_OUT_OF_MEMORY}, + {{'v','a','r',0xFEFF,' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK}, + {{'v','a','r',' ','a',' ','=',' ','1',';',' ',0xFEFF,'r','e','p','o','r','t','S','u','c','c','e','s','s','(',')',';','\0'}, S_OK}, + {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t',0xFEFF,'S','u','c','c','e','s','s','(',')',';','\0'}, JS_E_OUT_OF_MEMORY}, + {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s',0xFEFF,'(',')',';','\0'}, S_OK}, + {{'v','a','r',' ','a',' ','=',' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',0xFEFF,')',';','\0'}, S_OK}, + {{'v','a','r',' ','a',' ','=',0xFEFF,' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',0xFEFF,')',';','\0'}, S_OK}, + {{0xFEFF,'v','a','r',' ','a',' ','=',0xFEFF,0xFEFF,' ','1',';',' ','r','e','p','o','r','t','S','u','c','c','e','s','s','(',0xFEFF,')',';','\0'}, S_OK}, + {{0}} + }; + + engine_clsid = &CLSID_JScript; + + for (i = 0; bom_tests[i].str[0]; i++) + { + if(bom_tests[i].hres == S_OK) + { + SET_EXPECT(global_success_d); + SET_EXPECT(global_success_i); + src = SysAllocString(bom_tests[i].str); + hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); + ok(hres == S_OK, "test %s failed with %08x\n", wine_dbgstr_w(src), hres); + SysFreeString(src); + CHECK_CALLED(global_success_d); + CHECK_CALLED(global_success_i); + } + else + { + src = SysAllocString(bom_tests[i].str); + hres = parse_script(SCRIPTITEM_GLOBALMEMBERS, src); + todo_wine ok(hres == bom_tests[i].hres, "test %s returned with %08x\n", wine_dbgstr_w(src), hres); + SysFreeString(src); + } + } +} + static BOOL run_tests(void) { HRESULT hres; @@ -2259,6 +2310,8 @@ static BOOL run_tests(void) "Object expected", NULL); + run_bom_tests(); + return TRUE; }