From 3bb42a69583390208ee6f22332ab9b2e95d6b57f Mon Sep 17 00:00:00 2001 From: Eamonn Rea Date: Sun, 24 Mar 2024 03:39:13 +0000 Subject: [PATCH] updateConfigEntry: Fix sed expanding escape sequences Related to #1072. Stop sed from expanding escape sequences in strings. This function is used to save config entry items, and sed is expanding any backslashes in these options. There should never really be a case where we want config entry values to be expanded in this way, and also this is causing problems in #1072 where Windows paths using backslashes are mangled on initial save. Modify the sed command to use single-quotes for sed-specific syntax, and double quotes for variables, so they won't get expanded. This modifies an EXTREMELY core part of STL, so it will need extensive testing before it can be merged. --- steamtinkerlaunch | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/steamtinkerlaunch b/steamtinkerlaunch index 0006b8d2..66bbc26b 100755 --- a/steamtinkerlaunch +++ b/steamtinkerlaunch @@ -7,7 +7,7 @@ PREFIX="/usr" PROGNAME="SteamTinkerLaunch" NICEPROGNAME="Steam Tinker Launch" -PROGVERS="v14.0.20240323-1" +PROGVERS="v14.0.20240324-1 (updateConfigEntry-sed-prevent-escaping)" PROGCMD="${0##*/}" PROGINTERNALPROTNAME="Proton-stl" SHOSTL="stl" @@ -10921,17 +10921,24 @@ function updateConfigEntry { fi # only save value if it changed + # + # NOTE 24/03/2024 - the sed command was changed to prevent expanding escape sequences, + # i.e. removing backslashes from Windows paths, or interpreting `\t` as a tab character. + # please report if this causes problems! if { [ "${!CFGCAT}" != "$CFGVALUE" ] && [ "${!CFGCAT}" != "${CFGVALUE//$STLCFGDIR/STLCFGDIR}" ];} || [ -f "$FUPDATE" ]; then CFGVALUE="${CFGVALUE//$STLCFGDIR/STLCFGDIR}" if [ "$(grep -c "#${CFGCAT}=" "$CFGFILE")" -eq 1 ]; then writelog "INFO" "${FUNCNAME[0]} - Option '$CFGCAT' commented out in config '${CFGFILE##*/}' - activating it with the new value '$CFGVALUE'" - sed -i "/^#${CFGCAT}=/c$CFGCAT=\"$CFGVALUE\"" "$CFGFILE" + # sed -i "/^#${CFGCAT}=/c$CFGCAT=\"$CFGVALUE\"" "$CFGFILE" + sed -i '/^#'"${CFGCAT}"'=/c\'"${CFGCAT}=\"$CFGVALUE\"" "$CFGFILE" elif [ "$(grep -c "^${CFGCAT}=" "$CFGFILE")" -eq 0 ]; then writelog "INFO" "${FUNCNAME[0]} - '$CFGCAT' option missing in config '${CFGFILE##*/}' - adding a new line" - echo "$CFGCAT=\"$CFGVALUE\"" >> "$CFGFILE" + # echo "$CFGCAT=\"$CFGVALUE\"" >> "$CFGFILE" + printf "%s=\"%s\"\n" "${CFGCAT}" "${CFGVALUE}" >> "${CFGFILE}" else writelog "INFO" "${FUNCNAME[0]} - Option '$CFGCAT' is updated with the new value '$CFGVALUE' in config '${CFGFILE##*/}'" - sed -i "/^${CFGCAT}=/c$CFGCAT=\"$CFGVALUE\"" "$CFGFILE" + # sed -i "/^${CFGCAT}=/c$CFGCAT=\"$CFGVALUE\"" "$CFGFILE" + sed -i '/^'"${CFGCAT}"'=/c\'"${CFGCAT}=\"$CFGVALUE\"" "$CFGFILE" fi rm "$FUPDATE" 2>/dev/null fi