Fix regex exclude chars logic

https://github.com/webmin/webmin/pull/1776#discussion_r1017431635
This commit is contained in:
iliajie
2022-11-09 20:04:29 +02:00
parent ad9a5d7871
commit 163480b859

View File

@@ -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 {