Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Feb 2025 19:41:45 GMT
From:      Jamie Gritton <jamie@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: dc384b96228f - stable/14 - MFC jls: fix the -q option to put quotes around all whitespace PR:             283414
Message-ID:  <202502171941.51HJfjwB036103@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by jamie:

URL: https://cgit.FreeBSD.org/src/commit/?id=dc384b96228f1ffa64afe56abe636a2b6db66a48

commit dc384b96228f1ffa64afe56abe636a2b6db66a48
Author:     Jamie Gritton <jamie@FreeBSD.org>
AuthorDate: 2025-02-13 15:48:18 +0000
Commit:     Jamie Gritton <jamie@FreeBSD.org>
CommitDate: 2025-02-17 19:41:08 +0000

    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 c1cf074cd605..bd0bdfc83f2d 100644
--- a/usr.sbin/jls/jls.c
+++ b/usr.sbin/jls/jls.c
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502171941.51HJfjwB036103>