Mush unescapes \" character
edi9999 opened this issue · comments
Edgar Hipp commented
Here is my input.txt :
Hello "{{name}}"
Hello \"{{name}}\"
When running the mush command on this input, it does something strange with the escaped quotes here :
$ export name=John ; mush <input.txt
Hello "John"
Hello ""John""
Edgar Hipp commented
This seems to come from this line (highlighted with "=======")
echo "$line" | {
## parse undefined variables
sed -e "s#${LEFT_DELIM}[A-Za-z]*${RIGHT_DELIM}##g" | \
## parse comments
sed -e "s#${LEFT_DELIM}\!.*${RIGHT_DELIM}##g" | \
## escaping
sed -e 's/\\\"/""/g' # ========= This line
};
Line 131 in d8ee4db
Joseph Werle commented
@edi9999 do you see a fix?
Edgar Hipp commented
Removing the line :
sed -e 's/\\\"/""/g' # ========= This line
seems to fix the issue for me.
Joseph Werle commented
@edi9999 fixed!
Edgar Hipp commented
Hello @jwerle ,
This is not the right fix.
The line should be removed completely :
With your current fix, the behavior is like this :
input.txt :
Hello "{{name}}"
Hello \"{{name}}\"
output.txt :
Hello "John"
Hello "John"
But the output should be :
Hello "John"
Hello \"John\"
The right patch is to remove this sed line completely : sed -e 's/\\\"/""/g'
The script should be like this :
## read each line
while IFS= read -r line; do
printf '%q\n' "${line}" | {
## read each ENV variable
echo "$ENV" | {
while read -r var; do
## split each ENV variable by '='
## and parse the line replacing
## occurrence of the key with
## guarded by the values of
## `LEFT_DELIM' and `RIGHT_DELIM'
## with the value of the variable
case "$var" in
(*"="*)
key=${var%%"="*}
val=${var#*"="*}
;;
(*)
key=$var
val=
;;
esac
line="${line//${LEFT_DELIM}$key${RIGHT_DELIM}/$val}"
done
if [ "1" = "$ESCAPE" ]; then
line="${line//&/&}"
line="${line//\"/"}"
line="${line//\</<}"
line="${line//\>/>}"
fi
## output to stdout
echo "$line" | {
## parse undefined variables
sed -e "s#${LEFT_DELIM}[A-Za-z]*${RIGHT_DELIM}##g" | \
## parse comments
sed -e "s#${LEFT_DELIM}\!.*${RIGHT_DELIM}##g" | \
};
}
};
done
Joseph Werle commented
okay done!
Joseph Werle commented
fixed in 0.1.4