Skip to content

Commit

Permalink
common-utils.sh: Fix _json_escape function for OSX sed | Resolve #162
Browse files Browse the repository at this point in the history
  • Loading branch information
Akianonymus committed Jun 15, 2021
1 parent 5295b76 commit dd07a4d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
18 changes: 8 additions & 10 deletions sh/common-utils.sh
Expand Up @@ -183,19 +183,17 @@ _json_escape() {
# just for refrence "s|'|\'|g"
if [ "${mode_json_escape}" = "j" ]; then
output_json_escape="$(printf "%s" "${input_json_escape}" | sed \
-e "s|'\'|'\\'|g" \
-e "s|'/'|'\/'|g" \
-e "s|\\\|\\\\\\\|g" \
-e "s|\/|\\\/|g" \
-e 's/\"/\\\"/g' \
-e ':a; $!N' \
-e 's|\t|\\t|g' \
-e 's|\r|\\r|g' \
-e 's|\f|\\f|g')"
-e "s/$(printf '\t')/\\t/g" \
-e "s/$(printf '\r')/\\r/g" \
-e "s/$(printf '\f')/\\f/g")"
else
output_json_escape="$(printf "%s" "${input_json_escape}" | sed \
-e ':a; $!N' \
-e 's|\t|\\t|g' \
-e 's|\r|\\r|g' \
-e 's|\f|\\f|g')"
-e "s/$(printf '\t')/\\t/g" \
-e "s/$(printf '\r')/\\r/g" \
-e "s/$(printf '\f')/\\f/g")"
fi
# use awk because sed just messes up with newlines
output_json_escape="$(printf "%s" "${output_json_escape}" | awk '{printf "%s%s",sep,$0; sep="\\n"} END{print ""}')"
Expand Down
18 changes: 8 additions & 10 deletions sh/release/gsync
Expand Up @@ -184,19 +184,17 @@ _json_escape() {
# just for refrence "s|'|\'|g"
if [ "${mode_json_escape}" = "j" ]; then
output_json_escape="$(printf "%s" "${input_json_escape}" | sed \
-e "s|'\'|'\\'|g" \
-e "s|'/'|'\/'|g" \
-e "s|\\\|\\\\\\\|g" \
-e "s|\/|\\\/|g" \
-e 's/\"/\\\"/g' \
-e ':a; $!N' \
-e 's|\t|\\t|g' \
-e 's|\r|\\r|g' \
-e 's|\f|\\f|g')"
-e "s/$(printf '\t')/\\t/g" \
-e "s/$(printf '\r')/\\r/g" \
-e "s/$(printf '\f')/\\f/g")"
else
output_json_escape="$(printf "%s" "${input_json_escape}" | sed \
-e ':a; $!N' \
-e 's|\t|\\t|g' \
-e 's|\r|\\r|g' \
-e 's|\f|\\f|g')"
-e "s/$(printf '\t')/\\t/g" \
-e "s/$(printf '\r')/\\r/g" \
-e "s/$(printf '\f')/\\f/g")"
fi
# use awk because sed just messes up with newlines
output_json_escape="$(printf "%s" "${output_json_escape}" | awk '{printf "%s%s",sep,$0; sep="\\n"} END{print ""}')"
Expand Down
18 changes: 8 additions & 10 deletions sh/release/gupload
Expand Up @@ -184,19 +184,17 @@ _json_escape() {
# just for refrence "s|'|\'|g"
if [ "${mode_json_escape}" = "j" ]; then
output_json_escape="$(printf "%s" "${input_json_escape}" | sed \
-e "s|'\'|'\\'|g" \
-e "s|'/'|'\/'|g" \
-e "s|\\\|\\\\\\\|g" \
-e "s|\/|\\\/|g" \
-e 's/\"/\\\"/g' \
-e ':a; $!N' \
-e 's|\t|\\t|g' \
-e 's|\r|\\r|g' \
-e 's|\f|\\f|g')"
-e "s/$(printf '\t')/\\t/g" \
-e "s/$(printf '\r')/\\r/g" \
-e "s/$(printf '\f')/\\f/g")"
else
output_json_escape="$(printf "%s" "${input_json_escape}" | sed \
-e ':a; $!N' \
-e 's|\t|\\t|g' \
-e 's|\r|\\r|g' \
-e 's|\f|\\f|g')"
-e "s/$(printf '\t')/\\t/g" \
-e "s/$(printf '\r')/\\r/g" \
-e "s/$(printf '\f')/\\f/g")"
fi
# use awk because sed just messes up with newlines
output_json_escape="$(printf "%s" "${output_json_escape}" | awk '{printf "%s%s",sep,$0; sep="\\n"} END{print ""}')"
Expand Down

0 comments on commit dd07a4d

Please sign in to comment.