[PATCH v4 0/1] MR11278: vbscript: Count a bare carriage return as a line break in error reporting.
-- v4: vbscript: Count carriage returns as line endings when reporting error lines. https://gitlab.winehq.org/wine/wine/-/merge_requests/11278
From: Francis De Brabandere <francisdb@gmail.com> Native sees '\n', '\r' and '\r\n' as line endings. When reporting the line an error occurred on, we only counted '\n', so this adds the bare '\r' and '\r\n' endings we were missing. --- dlls/vbscript/tests/run.c | 36 ++++++++++++++++++++++++++++++++++++ dlls/vbscript/vbscript.c | 5 ++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/dlls/vbscript/tests/run.c b/dlls/vbscript/tests/run.c index bee738d236c..f597fa2c6e8 100644 --- a/dlls/vbscript/tests/run.c +++ b/dlls/vbscript/tests/run.c @@ -3745,6 +3745,41 @@ static void test_sub_decl_scope(void) } } +/* Native counts '\n', '\r' and '\r\n' as line endings, so a '\n\r' pair is + two. Each script ends with a failing statement preceded by two separators, + and the reported 0-based error line is the number of line endings before + it: 2 for the single-break styles, 4 for the doubled '\n\r' and '\r\r'. */ +static void test_error_line_endings(void) +{ + static const struct { + const WCHAR *src; + ULONG error_line; + } tests[] = { + { L"' a\n' b\nx = 1 \\ 0\n", 2 }, + { L"' a\r\n' b\r\nx = 1 \\ 0\r\n", 2 }, + { L"' a\r' b\rx = 1 \\ 0\r", 2 }, + { L"' a\n' b\rx = 1 \\ 0\r", 2 }, + { L"' a\r' b\nx = 1 \\ 0\n", 2 }, + { L"' a\n\r' b\n\rx = 1 \\ 0\n\r", 4 }, + { L"' a\r\r' b\r\rx = 1 \\ 0\r\r", 4 }, + { L"' a\r\n' b\rx = 1 \\ 0\r\n", 2 }, + }; + HRESULT hres; + unsigned i; + + for (i = 0; i < ARRAY_SIZE(tests); i++) { + error_line = ~0; + error_code = 0; + onerror_hres = S_OK; + SET_EXPECT(OnScriptError); + hres = parse_script_wr(tests[i].src); + CLEAR_CALLED(OnScriptError); + ok(hres == 0x80020101 && error_code == 11 && error_line == tests[i].error_line, + "[%u] %s: hres=%08lx code=%u line=%lu\n", i, wine_dbgstr_w(tests[i].src), + hres, error_code, error_line); + } +} + static void test_msgbox(void) { HRESULT hres; @@ -4443,6 +4478,7 @@ static void run_tests(void) test_parse_errors(); test_class_decl_scope(); test_sub_decl_scope(); + test_error_line_endings(); test_redefine_scope(); test_getref_error_reporting(); test_getref_external_caller_error(); diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c index a4cfeea9eab..9a42f7009bd 100644 --- a/dlls/vbscript/vbscript.c +++ b/dlls/vbscript/vbscript.c @@ -688,7 +688,10 @@ HRESULT report_script_error(script_ctx_t *ctx, vbscode_t *code, unsigned loc, BO error->cookie = code->cookie; error->line = code->start_line; for(nl = p = code->source; p < code->source + loc; p++) { - if(*p != '\n') continue; + /* A bare '\r' (classic Mac line ending) starts a new line just like + '\n'; a '\r\n' pair counts as a single line, tallied on the '\n'. */ + if(*p != '\n' && (*p != '\r' || p[1] == '\n')) + continue; error->line++; nl = p + 1; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11278
This merge request was approved by Jacek Caban. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/11278
participants (3)
-
Francis De Brabandere -
Francis De Brabandere (@francisdb) -
Jacek Caban (@jacek)