MINOR: cli: allow the semi-colon to be escaped on the CLI
Today I was working on an auto-update script for some ACLs, and found
that I couldn't load ACL entries with a semi-colon in them no matter
how I tried to escape it.
As such, I wrote this patch (this one is for 1.7dev, but it applies to
1.5 the same with just line numbers changed), which seems to allow me
to execute a command such as "add acl /etc/foo.lst foo\;bar" over the
socket. It's worth noting that stats_sock_parse_request() already uses
the backslash to escape spaces in words so it makes sense to use it as
well to escape the semi-colon.
(cherry picked from commit e3f5031b5186367d8559dad5170cf88bff923a04)
(cherry picked from commit 1263b32b7c5cb5d9af83d951ae7fbaa581209470)
diff --git a/doc/configuration.txt b/doc/configuration.txt
index 123ed97..a622fe3 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -13411,6 +13411,9 @@
# echo "show info;show stat;show table" | socat /var/run/haproxy stdio
+If a command needs to use a semi-colon (eg: in a value), it must be preceeded
+by a backslash ('\').
+
The interactive mode displays a prompt ('>') and waits for commands to be
entered on the line, then processes them, and displays the prompt again to wait
for a new command. This mode is entered via the "prompt" command which must be
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 7347af4..3b1e5e5 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -2284,15 +2284,20 @@
continue;
}
- /* seek for a possible semi-colon. If we find one, we
- * replace it with an LF and skip only this part.
+ /* seek for a possible unescaped semi-colon. If we find
+ * one, we replace it with an LF and skip only this part.
*/
- for (len = 0; len < reql; len++)
+ for (len = 0; len < reql; len++) {
+ if (trash.str[len] == '\\') {
+ len++;
+ continue;
+ }
if (trash.str[len] == ';') {
trash.str[len] = '\n';
reql = len + 1;
break;
}
+ }
/* now it is time to check that we have a full line,
* remove the trailing \n and possibly \r, then cut the