]> git.sesse.net Git - plocate/commit
Escape unprintable characters when outputting filenames to a terminal.
authorSteinar H. Gunderson <steinar+git@gunderson.no>
Thu, 29 Oct 2020 22:42:01 +0000 (23:42 +0100)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Thu, 29 Oct 2020 22:42:01 +0000 (23:42 +0100)
commitcbecd483f57c465b2ad6d3867c760c2e5b5e79aa
tree4fd90241fa1a31484287058352e5e53fab837675
parent93d57f8f19e57efbb91e139bfca1064bd9e27bb3
Escape unprintable characters when outputting filenames to a terminal.

Filenames are generally untrusted, and can contain any kind of cruft.
In particular, there have been terminals (hopefully not in wide use anymore!)
that will do insanity like running specific commands when seeing a
specific escape sequence. More prosaically, embedded newlines can
make for confusing output.

Thus, escape any nonprintable characters in a shell-parseable way,
much the same way GNU ls does these days. Also escape quotes, backslashes
and the likes to make sure nothing unescaped looks like it's escaped.
This doesn't mean it's safe to take whatever and parse it uncritically
(we don't escape $, for instance), but it's generally good enough.

Escaping is disabled when doing zero-terminated output, or when printing
to a pipe or file.
options.h
plocate.cpp
serializer.cpp