Skip to content

Commit

Permalink
roundtrip: Fix handling of trailing newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
b4n committed Nov 29, 2017
1 parent 4bae9ed commit cd6c100
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions misc/roundtrip
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,20 @@ IFS='
set -x
for tags in $(find "$UNITS" -name expected.tags); do
for name in $(sed -e 's/^\([^ ]*\) .*/\1/' "$tags"); do
# don't expand in the loop to handle "\n" sequence properly
t="$(printf '%s' "$name" | expandEscapeSequences)"
# Yes, there is a reason for this craziness. We need to properly
# handle embedded newlines (expanded from "\n"), including trailing
# ones the shell would strip automatically. To work around this, we
# add a dummy character at the end to inhibit stripping, and then
# remove it, plus the extra newline, using variable substitutions.
# Note: we use "printf '%s\n'" instead of "echo" because Dash's "echo"
# unconditionally expands some sequences, like "\t" and alike.
t="$(printf '%s\n' "$name" | expandEscapeSequences; printf _)"
t="${t%
_}"

if [ 1 -gt $("${READTAGS}" -t "$tags" - "$t" 2>/dev/null | wc -l) ]; then
printf 'FAILED: "%s" -t "%s" - "%s"\n' "${READTAGS}" "$tags" "$t"
printf ' The raw tag name was "%s"\n' "$name"
s=1
fi
done
Expand Down

0 comments on commit cd6c100

Please sign in to comment.