Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
0795-ct-ct_telnet-fix-prompt-search-with-unicod...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0795-ct-ct_telnet-fix-prompt-search-with-unicode-chars.patch of Package erlang
From 1242070f12cbccd7c6236b1c43695958733a5057 Mon Sep 17 00:00:00 2001 From: Jakub Witczak <kuba@erlang.org> Date: Wed, 28 Jun 2023 17:52:54 +0200 Subject: [PATCH] ct: ct_telnet fix prompt search with unicode chars --- lib/common_test/src/ct_telnet.erl | 59 +++++++++++++------------- lib/common_test/test/telnet_server.erl | 2 +- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/lib/common_test/src/ct_telnet.erl b/lib/common_test/src/ct_telnet.erl index d6c69329ad..89190de81e 100644 --- a/lib/common_test/src/ct_telnet.erl +++ b/lib/common_test/src/ct_telnet.erl @@ -1224,37 +1224,36 @@ split_lines([Char|Rest],Line,Lines) -> split_lines([],Line,Lines) -> {Lines,lists:reverse(Line)}. - -match_prompt(Str,Prx) -> - match_prompt(Str,Prx,[]). -match_prompt(Str,Prx,Acc) -> +match_prompt(Str, Prx) -> + match_prompt(unicode:characters_to_binary(Str), Prx, []). +match_prompt(Str, Prx, Acc) -> case re:run(Str,Prx,[unicode]) of - nomatch -> - noprompt; - {match,[{Start,Len}]} -> - case split_prompt_string(Str,Start+1,Start+Len,1,[],[]) of - {noprompt,Done,Rest} -> - match_prompt(Rest,Prx,Done); - {prompt,UptoPrompt,Prompt,Rest} -> - {prompt,lists:reverse(UptoPrompt++Acc), - lists:reverse(Prompt),Rest} - end + nomatch -> + noprompt; + {match,[{Start,Len}]} -> + <<UptoPrompt:Start/binary, Prompt:Len/binary, Rest/binary>> = Str, + case validate_prompt(Start, UptoPrompt, Prompt) of + ok -> + {prompt, + unicode:characters_to_list([lists:reverse(Acc), UptoPrompt, Prompt]), + unicode:characters_to_list(Prompt), + unicode:characters_to_list(Rest)}; + recurse -> + <<Skip:(Start+Len)/binary, Cont/binary>> = Str, + match_prompt(Cont, Prx, [Skip|Acc]) + end end. -split_prompt_string([Ch|Str],Start,End,N,UptoPrompt,Prompt) when N<Start -> - split_prompt_string(Str,Start,End,N+1,[Ch|UptoPrompt],Prompt); -split_prompt_string([Ch|Str],Start,End,N,UptoPrompt,Prompt) - when N>=Start, N<End-> - split_prompt_string(Str,Start,End,N+1,UptoPrompt,[Ch|Prompt]); -split_prompt_string([Ch|Rest],_Start,End,N,UptoPrompt,Prompt) when N==End -> - case UptoPrompt of - [$",$=,$T,$P,$M,$O,$R,$P|_] -> - %% This is a line from "listenv", it is not a real prompt - {noprompt,[Ch|Prompt]++UptoPrompt,Rest}; - [$\s,$t,$s,$a|_] when Prompt==":nigol" -> - %% This is probably the "Last login:" statement which is - %% written when telnet connection is opened. - {noprompt,[Ch|Prompt]++UptoPrompt,Rest}; - _ -> - {prompt,[Ch|Prompt]++UptoPrompt,[Ch|Prompt],Rest} +validate_prompt(Size, PrePrompt, Prompt) -> + case PrePrompt of + %% This is a line from "listenv", it is not a real prompt + <<_:(Size-8)/binary, "PROMPT=\"", _/binary>> -> + recurse; + %% This is probably the "Last login:" statement which is + %% written when telnet connection is opened. + <<_:(Size-5)/binary, _L:8, "ast ", _/binary>> + when Prompt =:= <<"login: ">> -> + recurse; + _ -> + ok end. diff --git a/lib/common_test/test/telnet_server.erl b/lib/common_test/test/telnet_server.erl index cef7784333..117b1b9f6d 100644 --- a/lib/common_test/test/telnet_server.erl +++ b/lib/common_test/test/telnet_server.erl @@ -306,7 +306,7 @@ check_user(User,State) -> check_pwd(Pwd,#state{authorized={user,Pwd}}=State) -> dbg("password ok\n"), - send("Welcome to the ultimate telnet server!\r\n> ",State), + send("Welcomé to the ultimate telnet server!\r\n> ",State), {ok,State#state{authorized=true}}; check_pwd(_,_State) -> throw({error,authentication}). -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor