From 163480b8591cdc4ccabccef4ff112d778afd1ced Mon Sep 17 00:00:00 2001 From: iliajie Date: Wed, 9 Nov 2022 20:04:29 +0200 Subject: [PATCH] Fix regex exclude chars logic https://github.com/webmin/webmin/pull/1776#discussion_r1017431635 --- xterm/shellserver.pl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/xterm/shellserver.pl b/xterm/shellserver.pl index b5288eb0b..c2a3e4f93 100755 --- a/xterm/shellserver.pl +++ b/xterm/shellserver.pl @@ -117,12 +117,15 @@ Net::WebSocket::Server->new( exit(0); } if ($wsconn) { - # Do not print commands to display, if start from two - # consecutive spaces and ends with return char. This - # regex only catches commands sent in one shot using - # socket.send(' command\r') call, i.e. it won't work - # if command is pasted or typed in a normal way - $buf =~ s/^[\s]{2}\S+.*[\r\n]+[\e]\[\?2004l[\n]*//; + # Do not print commands to display, if start from two and more spaces + # and ends with return char. Number of preceding spaces should equal + # the length of a command being executed. This regex only catches + # commands sent in one shot using socket.send(' ls\r') call, i.e. + # it won't work if command is pasted or typed in a normal way + if ($buf =~ /^([\s]{2,})(\S+.*)[\r\n]+[\e]\[\?2004l[\n]*/) { + $buf =~ s/^[\s]{2,}\S+.*[\r\n]+[\e]\[\?2004l[\n]*// + if (length($1) == length($2)); + } $wsconn->send_binary($buf); } else {