diff options
author | Jean Delvare <jdelvare@suse.de> | 2017-05-02 15:02:49 +0200 |
---|---|---|
committer | Jean Delvare <jdelvare@suse.de> | 2017-05-02 15:02:49 +0200 |
commit | 102ab72dc48297be33d62dbe73536a714bcbf464 (patch) | |
tree | 99759ab1a50547776b6451b229a01e16432982b2 | |
parent | 7080e2ad44f79a2660d5d56c24b6dff846b32260 (diff) | |
download | quilt-102ab72dc48297be33d62dbe73536a714bcbf464.tar.gz |
header: Fix patch corruption when trailing newline is missing
When editing a patch header with certain editors, it is possible that
no trailing newline character is present on the last line. In such
case, the patch would be corrupted. Prevent that by ensuring that a
newline character is always present.
This fixes bug #50841:
https://savannah.nongnu.org/bugs/?50841
Signed-off-by: Jean Delvare <jdelvare@suse.de>
-rw-r--r-- | quilt/header.in | 7 | ||||
-rw-r--r-- | test/header.test | 13 |
2 files changed, 20 insertions, 0 deletions
diff --git a/quilt/header.in b/quilt/header.in index 6a9121f..c01778f 100644 --- a/quilt/header.in +++ b/quilt/header.in @@ -154,6 +154,13 @@ else LANG=$ORIGINAL_LANG $EDITOR "$tmp" || exit 1 fi + # Ensure there is a trailing newline before we append the rest + last_char=$(tail -c 1 "$tmp") + if ! [ -z "$last_char" -o "$last_char" = $'\n' -o "$last_char" = $'\r' ] + then + echo "" >> $tmp + fi + maybe_strip_diffstat < $tmp \ | maybe_strip_trailing_whitespace > $tmp2 diff --git a/test/header.test b/test/header.test index f6367b5..7e0cbca 100644 --- a/test/header.test +++ b/test/header.test @@ -42,3 +42,16 @@ > @@ -1 +1 @@ > -foo > +bar + + $ echo -n "No trailing newline" | quilt header -r + > Replaced header of patch patches/patch + + $ cat patches/patch + > No trailing newline + > Index: b/foo + > =================================================================== + > --- a/foo + > +++ b/foo + > @@ -1 +1 @@ + > -foo + > +bar |