common/utils: Add uri_quote and tests
commit9d568b571be65b8f3f35890e788ccc326dd6859f
authorEric Blake <eblake@redhat.com>
Wed, 26 Jun 2019 16:05:05 +0000 (26 11:05 -0500)
committerEric Blake <eblake@redhat.com>
Wed, 26 Jun 2019 17:04:31 +0000 (26 12:04 -0500)
tree96bc1fd759092ba15aef7f535b602aa5680ee9c7
parentbf6eae91e8fd83b5905473ecf3fd3a634f18d361
common/utils: Add uri_quote and tests

Normally, when using captive mode --run coupled with a Unix socket,
the user is using -U -, and we get lucky that the typcial values of
$TMPDIR plus our use of mktemp produce a name that needs neither shell
quoting nor which requires %-encoding for use in a URI.  But a
determined user can use an explicit -U /odd/#path or setting of
$TMPDIR that gets correctly shell-quoted, but which would break
interpretation in a URI parser. In preparation for adding a $uri
variable under --run, it's time to ensure that we can always produce a
valid unambiguous URI by adding a new helper function.  It is
intentional that uri_quote of an empty string produces no output, as
the intended audience of uri_quote is always a smaller component
within a larger URI (different from shell_quote which does have use on
a stand-alone empty string).

It's also worth testing the existing shell_quote (including the bug
fixed in bdda3f30) as well as the new uri_quote.  The test includes an
XXX comment that matches the counterpart XXX in shell_quote(); an
audit of shell_quote() callers shows that the iso plugin might be
affected if someone ever used prog=a=b, but that is fringe enough to
put off to another day.

Signed-off-by: Eric Blake <eblake@redhat.com>
.gitignore
common/utils/Makefile.am
common/utils/test-quotes.c [new file with mode: 0644]
common/utils/utils.c
common/utils/utils.h