fix: escape special characters in restore_ini sed replacement

- Add escaping for &, /, and \ in values restored from backup
- Prevent sed substitution from breaking when URLs or special chars are present
This commit is contained in:
taamarin
2025-09-04 09:13:21 +07:00
parent 6a3acff87c
commit ff44bf3b1f

View File

@@ -197,9 +197,13 @@ restore_ini() {
for key in $keys; do
value=$(grep "^$key=" "$backup_ini")
if [ -n "$value" ]; then
# Escape special characters to make it safe for sed
esc_value=$(printf '%s\n' "$value" | sed -e 's/[&/\]/\\&/g')
if grep -q "^$key=" "$target_ini"; then
# Replace old line
sed -i "s|^$key=.*|$value|" "$target_ini"
# sed -i "s|^$key=.*|$value|" "$target_ini"
sed -i "s|^$key=.*|$esc_value|" "$target_ini"
else
# Append at the end of the file
echo "$value" >> "$target_ini"