From c5ef84193d601524670fe53ea427c82f1bb4e1a3 Mon Sep 17 00:00:00 2001 From: cschantz Date: Fri, 21 Nov 2025 17:35:02 -0500 Subject: [PATCH] CRITICAL: Fix grep regex errors when usernames contain special characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ROOT CAUSE: Usernames containing bracket characters like '[' or ']' were being used directly in grep patterns, causing: grep: Unmatched [, [^, [:, [., or [= This happened during "Indexing users" when the reference database builder called get_user_domains/get_user_databases with usernames containing brackets. AFFECTED FUNCTIONS (lib/user-manager.sh): - get_interworx_user_domains() line 284: grep -v "^${username}\." - get_interworx_user_info() line 195: grep -A20 with $primary_domain - get_user_processes() line 583: grep "^${username}" - get_user_top_processes() line 590: grep "^${username}" AFFECTED FUNCTIONS (lib/reference-db.sh): - index_wordpress_sites() line 420: grep "^USER|${username}|" THE FIX: Changed all grep commands using variables in patterns to use -F (fixed string) flag instead of regex matching, and added 2>/dev/null error suppression: OLD: grep "^${username}" NEW: grep -F "$username" 2>/dev/null OLD: grep -v "^${username}\." NEW: grep -vF "${username}." 2>/dev/null IMPACT: Eliminates ALL "Unmatched [" errors during reference database build, even when usernames contain special regex characters: [].*+?^$(){}| 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/reference-db.sh | 2 +- lib/user-manager.sh | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/reference-db.sh b/lib/reference-db.sh index 8ad91c0..be6b2c6 100755 --- a/lib/reference-db.sh +++ b/lib/reference-db.sh @@ -417,7 +417,7 @@ build_wordpress_section() { # Check for common domain folder patterns if [[ "$path_after_home" == public_html ]]; then # This is the primary domain - get it from user info - domain=$(grep "^USER|${username}|" "$SYSREF_DB" | cut -d'|' -f3 || true) + domain=$(grep -F "USER|${username}|" "$SYSREF_DB" 2>/dev/null | cut -d'|' -f3 || true) elif [[ "$path_after_home" =~ ^public_html/(.+) ]]; then # Could be subdomain or subdirectory - extract folder name local folder=$(echo "$path_after_home" | cut -d'/' -f2) diff --git a/lib/user-manager.sh b/lib/user-manager.sh index 42553d6..d5ebdba 100755 --- a/lib/user-manager.sh +++ b/lib/user-manager.sh @@ -192,8 +192,8 @@ get_interworx_user_info() { local email="" if [ -x "/usr/local/interworx/bin/nodeworx.pex" ] && [ -n "$primary_domain" ]; then email=$(nodeworx -u -n -c Siteworx -a listAccounts 2>/dev/null | \ - grep -A20 "\"domain\" => \"$primary_domain\"" | \ - grep "\"email\"" | head -1 | sed 's/.*=> "\(.*\)".*/\1/') + grep -F "\"domain\" => \"$primary_domain\"" 2>/dev/null | head -1 | \ + grep "\"email\"" 2>/dev/null | head -1 | sed 's/.*=> "\(.*\)".*/\1/') fi echo "USER_EXISTS=yes" @@ -281,7 +281,7 @@ get_interworx_user_domains() { if [ -d "/etc/httpd/conf.d" ]; then grep -l "SuexecUserGroup ${username}" /etc/httpd/conf.d/vhost_*.conf 2>/dev/null | \ sed 's|.*/vhost_||; s|\.conf$||' | \ - grep -v "^${username}\." | \ + grep -vF "${username}." 2>/dev/null | \ sort -u fi } @@ -580,14 +580,14 @@ select_user_interactive() { get_user_processes() { local username="$1" - ps aux | grep "^${username}" | grep -v grep + ps aux | grep -F "$username" 2>/dev/null | grep -v grep } get_user_top_processes() { local username="$1" local limit="${2:-10}" - ps aux | grep "^${username}" | grep -v grep | sort -k3 -rn | head -n "$limit" + ps aux | grep -F "$username" 2>/dev/null | grep -v grep | sort -k3 -rn | head -n "$limit" } #############################################################################