Fix append-file concatenating without a newline (#204)#233
Conversation
add801f to
5a2164c
Compare
|
@MartinEbner reworked since #243's description was written — this no longer touches Worth flagging: #243 as written does not fix #204 — its @vsbogd ready for review. |
|
Thanks for the ping — agreed on both counts. #243 doesn't claim to fix #204: its The two compose cleanly, and whichever lands second does the small port. If this one lands first, #243 picks up the line-start guard in |
5a2164c to
cba3197
Compare
append-file appends a line but only guarantees a newline after the text, never before it. When the file does not already end with a newline, which is what the byte-exact write-file leaves behind, the appended line does not start on a new line and the contents are silently merged. Add line_separator/2 to emit a newline before appending when the file does not already end at a line start. write-file remains byte-exact.
cba3197 to
d2eaf80
Compare
Description
Fixes #204.
append-fileis documented as appending a line ("a trailing newline is always added"), but it only adds the newline after the text, never before it. When the file does not already end with a newline — which is what the byte-exactwrite-fileleaves behind — the appended line does not start on a new line and the content silently merges (eggs+cheese→eggscheese).Adds
line_separator/2toskills.pl, which emits a newline before the append only when the file is not already at a line start.write-fileis untouched and stays byte-exact, per @vsbogd's comment on the issue.How Has This Been Tested?
write-file "/tmp/s.txt" "milk, bread, eggs"thenappend-file "/tmp/s.txt" "cheese, apples"→milk, bread, eggs\ncheese, apples\n, the output the issue expects.append-file→ no double blank line;append-fileto an empty file → no leading blank line.write-file "/tmp/f.txt" ""→ still 0 bytes,write-file "/tmp/f.txt" "Hello"→ stillHello.write-filebehaviour is unchanged, sotest_create_file/test_create_empty_fileare unaffected.Checklist