MFC jls: fix the -q option to put quotes around all whitespace

PR:		283414

(cherry picked from commit 3d11af1e595b5a3646be370e33c4aa850dc62bb0)
This commit is contained in:
Jamie Gritton 2025-02-13 07:48:18 -08:00
parent 486af41443
commit dc384b9622

View file

@ -38,6 +38,7 @@
#include <arpa/inet.h>
#include <netinet/in.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <jail.h>
@ -516,13 +517,21 @@ quoted_print(int pflags, char *name, char *value)
}
/*
* The value will be surrounded by quotes if it contains spaces
* or quotes.
* The value will be surrounded by quotes if it contains
* whitespace or quotes.
*/
qc = strchr(p, '\'') ? '"'
: strchr(p, '"') ? '\''
: strchr(p, ' ') || strchr(p, '\t') ? '"'
: 0;
if (strchr(p, '\''))
qc = '"';
else if (strchr(p, '"'))
qc = '\'';
else {
qc = 0;
for (; *p; ++p)
if (isspace(*p)) {
qc = '"';
break;
}
}
if (qc && pflags & PRINT_QUOTED)
xo_emit("{P:/%c}", qc);