Skip to content

Commit

Permalink
updateConfigEntry: Fix sed expanding escape sequences
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sonic2kk committed Mar 24, 2024
1 parent bedf6e7 commit 3bb42a6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions steamtinkerlaunch
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3bb42a6

Please sign in to comment.