From dc384b96228f1ffa64afe56abe636a2b6db66a48 Mon Sep 17 00:00:00 2001 From: Jamie Gritton Date: Thu, 13 Feb 2025 07:48:18 -0800 Subject: [PATCH] MFC jls: fix the -q option to put quotes around all whitespace PR: 283414 (cherry picked from commit 3d11af1e595b5a3646be370e33c4aa850dc62bb0) --- usr.sbin/jls/jls.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/usr.sbin/jls/jls.c b/usr.sbin/jls/jls.c index c1cf074cd60..bd0bdfc83f2 100644 --- a/usr.sbin/jls/jls.c +++ b/usr.sbin/jls/jls.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -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);