git: 3d11af1e595b - main - jls: fix the -q option to put quotes around all whitespace PR: 283414
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 13 Feb 2025 23:49:04 UTC
The branch main has been updated by jamie:
URL: https://cgit.FreeBSD.org/src/commit/?id=3d11af1e595b5a3646be370e33c4aa850dc62bb0
commit 3d11af1e595b5a3646be370e33c4aa850dc62bb0
Author: Jamie Gritton <jamie@FreeBSD.org>
AuthorDate: 2025-02-13 15:48:18 +0000
Commit: Jamie Gritton <jamie@FreeBSD.org>
CommitDate: 2025-02-13 15:48:18 +0000
jls: fix the -q option to put quotes around all whitespace
PR: 283414
---
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 e172c4698f57..2d173a29ac40 100644
--- a/usr.sbin/jls/jls.c
+++ b/usr.sbin/jls/jls.c
@@ -37,6 +37,7 @@
#include <arpa/inet.h>
#include <netinet/in.h>
+#include <ctype.h>
#include <errno.h>
#include <jail.h>
#include <limits.h>
@@ -515,13 +516,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);