git: 58a8f100a6fd - main - safe_eval.sh: safe_set_var use [:space:] if possible

From: Simon J. Gerraty <sjg_at_FreeBSD.org>
Date: Sun, 11 Oct 2026 21:55:18 UTC
The branch main has been updated by sjg:

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

commit 58a8f100a6fdb84997ed4740bd794779375e376f
Author:     Simon J. Gerraty <sjg@FreeBSD.org>
AuthorDate: 2026-10-11 21:55:11 +0000
Commit:     Simon J. Gerraty <sjg@FreeBSD.org>
CommitDate: 2026-10-11 21:55:11 +0000

    safe_eval.sh: safe_set_var use [:space:] if possible
    
    Also use $ssv_extra$ssv_only as the default for $ssv_only has '-'
    which must be last in the character class.
---
 libexec/rc/safe_eval.sh | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/libexec/rc/safe_eval.sh b/libexec/rc/safe_eval.sh
index 597c9e79ef9e..0fd085869397 100644
--- a/libexec/rc/safe_eval.sh
+++ b/libexec/rc/safe_eval.sh
@@ -1,6 +1,6 @@
 :
 # RCSid:
-#	$Id: safe_eval.sh,v 1.34 2026/10/11 18:08:28 sjg Exp $
+#	$Id: safe_eval.sh,v 1.35 2026/10/11 21:48:58 sjg Exp $
 #
 #	@(#) Copyright (c) 2023-2026 Simon J. Gerraty
 #
@@ -57,8 +57,13 @@ fi
 # If we pass all that, we eval "var=val" and return 0.
 #
 safe_set_var() {
-    eval $_local ssv_allow ssv_extra ssv_only ssv_rc
-    ssv_only="A-Za-z0-9_. 	\$,/=:+-"
+    eval $_local ssv_allow ssv_extra ssv_only ssv_space ssv_rc
+    # use [:space:] if we can as it includes \n
+    case " " in
+    [[:space:]]) ssv_space="[:space:]";;
+    *) ssv_space=" 	";;
+    esac
+    ssv_only="${ssv_space}A-Za-z0-9_.,/=:+\$-"
     ssv_rc=
 
     while :
@@ -84,9 +89,9 @@ safe_set_var() {
         ssv_rc=1
         ;;
     esac
-    : is ssv_val ok - "$ssv_val"
+    : is ssv_val ok - "$ssv_val" match only [$ssv_extra$ssv_only]
     case "$ssv_val" in
-    *[!$ssv_only$ssv_extra]*)
+    *[!$ssv_extra$ssv_only]*)
         ssv_val=invalid
         ssv_rc=${ssv_rc:-2}
         ;;