From 305de1707e5949c9225c5244f9dd716ad0db3d75 Mon Sep 17 00:00:00 2001
From: Luca Bilke <luca@bil.ke>
Date: Thu, 17 Oct 2024 11:53:06 +0200
Subject: [PATCH] redact_git_filter: properly escape strings

---
 common/.local/libexec/redact_git_filter | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/common/.local/libexec/redact_git_filter b/common/.local/libexec/redact_git_filter
index f4e22760..45ad85f6 100755
--- a/common/.local/libexec/redact_git_filter
+++ b/common/.local/libexec/redact_git_filter
@@ -6,9 +6,10 @@ GS="$(printf '\034')"
 
 map=$(jq -r 'to_entries[] | "\(.key)'"$FS"'\(.value)"' "${HOME}/.secrets/dotfile-secrets.json")
 
+awk='{gsub(/[^\^]/, "[&]", $2); gsub(/\^/, "\\^", $2);'
 case $1 in
-    clean) awk='{printf "s%s%s%s<#%s#>%sg;", d, $2, d, $1, d }' ;;
-    smudge) awk='{printf "s%s<#%s#>%s%s%sg;", d, $1, d, $2, d }' ;;
+    clean) awk="${awk}"' printf "s%s%s%s<#%s#>%sg;", d, $2, d, $1, d}' ;;
+    smudge) awk="${awk}"' printf "s%s<#%s#>%s%s%sg;", d, $1, d, $2, d}' ;;
 esac
 
 sed "$(echo "$map" | awk -F"$FS" -v d="$GS" "$awk")"