diff --git a/init.sh b/init.sh index 0c630bd..d12ce28 100755 --- a/init.sh +++ b/init.sh @@ -338,14 +338,23 @@ initUpdateConfigOption() { for config_file in "$category_dir"/*; do if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then if grep -q "^$config_option=" "$config_file"; then - local escaped_value=$(printf '%s\n' "$config_value" | sed -e 's/[\/&]/\\&/g') + # Use SOH (\x01) as the s-command delimiter — it can't appear + # in text-based config values or comments, so no field needs + # to escape the delimiter. The replacement field DOES need + # `&` (whole-match insertion) and `\` (escape char) neutralised + # in BOTH the value AND the comment — comments like + # `# Installation Mode - ...[release|git|local]` previously + # broke the `|`-delimited form with "unknown option to `s'". + local DELIM=$'\x01' + local escaped_value=$(printf '%s' "$config_value" | sed -e 's/[\\&]/\\&/g') local original_line=$(grep "^$config_option=" "$config_file") local comment_part=$(echo "$original_line" | sed -n "s|^$config_option=[^#]*\(#.*\)|\1|p") + local escaped_comment=$(printf '%s' "$comment_part" | sed -e 's/[\\&]/\\&/g') if [[ -n "$comment_part" ]]; then - sed -i "s|^$config_option=.*|$config_option=$escaped_value $comment_part|" "$config_file" + sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value $escaped_comment${DELIM}" "$config_file" else - sed -i "s|^$config_option=.*|$config_option=$escaped_value|" "$config_file" + sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value${DELIM}" "$config_file" fi source "$config_file" return 0 @@ -1249,18 +1258,24 @@ commandUpdateConfigOption() { for config_file in "$category_dir"/*; do if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then if grep -q "^$config_option=" "$config_file"; then - # Escape special characters in the config value to prevent sed issues - local escaped_value=$(printf '%s\n' "$config_value" | sed -e 's/[\/&]/\\&/g') + # Use SOH (\x01) as the s-command delimiter — it can't appear + # in text-based config values or comments, so no field needs + # to escape the delimiter. The replacement field DOES need + # `&` (whole-match insertion) and `\` (escape char) neutralised + # in BOTH the value AND the comment — comments like + # `# Installation Mode - ...[release|git|local]` previously + # broke the `|`-delimited form with "unknown option to `s'". + local DELIM=$'\x01' + local escaped_value=$(printf '%s' "$config_value" | sed -e 's/[\\&]/\\&/g') # Extract the comment part first (everything after the first #) local original_line=$(grep "^$config_option=" "$config_file") local comment_part=$(echo "$original_line" | sed -n "s|^$config_option=[^#]*\(#.*\)|\1|p") - - # Replace the value, preserving comment if it existed + local escaped_comment=$(printf '%s' "$comment_part" | sed -e 's/[\\&]/\\&/g') if [[ -n "$comment_part" ]]; then - sed -i "s|^$config_option=.*|$config_option=$escaped_value $comment_part|" "$config_file" + sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value $escaped_comment${DELIM}" "$config_file" else - sed -i "s|^$config_option=.*|$config_option=$escaped_value|" "$config_file" + sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value${DELIM}" "$config_file" fi source "$config_file" return 0