Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no end-of-line bug #295

Merged
merged 9 commits into from
Mar 29, 2020
Merged

Fix no end-of-line bug #295

merged 9 commits into from
Mar 29, 2020

Conversation

inkarkat
Copy link
Member

This fixes #294 by passing the target file through sed (when adding or moving, both of which use simple >> shell redirection which is susceptible to this) to add a trailing newline (EOL) character if one is missing.

Before submitting a pull request, please make sure the following is done:

  • Fork the repository and create your branch from master.
  • If you've added code that should be tested, add tests!
  • Ensure the test suite passes.
  • Format your code with ShellCheck.
  • Include a human-readable description of what the pull request is trying to accomplish.
  • Steps for the reviewer(s) on how they can manually QA the changes.
  • Have a fixes #XX reference to the issue that this pull request fixes.

This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file.
In _addto(), ensure a trailing newline via sed (taken from https://unix.stackexchange.com/a/31955/18876).

Fixes todotxt#294
This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file.
@inkarkat inkarkat requested a review from karbassi March 27, 2020 17:02
@inkarkat
Copy link
Member Author

@karbassi Somehow, the CI build isn't triggered on this: This branch has not been deployed; I was able to restart an old PR build in Travis, so that still works; maybe the GitHub trigger didn't work. I don't have admin rights to check this.

It's gotten a bit silent here; I've answered a few issues and PRs in the past, but other than that, not much has happened. If you could briefly review my two other open PRs (#271 and #273), I would merge them all in soon. I hope you're fine!

@karbassi
Copy link
Member

@inkarkat we might want to move over to Github Actions at some point.

I ran the tests and it failed.

cd tests && ./t1850-move.sh 
* FAIL 1: basic move with implicit source 1
todo.sh -f move 1 done.txt | sed "s#'[^']\+/\([^/']\+\)'#'\1'#g" 
--- expect	2020-03-27 18:37:30.000000000 +0000
+++ output	2020-03-27 18:37:30.000000000 +0000
@@ -1,2 +1,2 @@
 1 (B) smell the uppercase Roses +flowers @outside
-TODO: 1 moved from 'todo.txt' to 'done.txt'.
+TODO: 1 moved from 'tests/trash directory.t1850-move/todo.txt' to 'tests/trash directory.t1850-move/done.txt'.
*   ok 2: basic move with implicit source 2
*   ok 3: basic move with implicit source 3
* FAIL 4: basic move with passed source 1
todo.sh -f move 2 todo.txt done.txt | sed "s#'[^']\+/\([^/']\+\)'#'\1'#g" 
--- expect	2020-03-27 18:37:30.000000000 +0000
+++ output	2020-03-27 18:37:30.000000000 +0000
@@ -1,2 +1,2 @@
 2 x 2009-02-13 smell the coffee +wakeup
-TODO: 2 moved from 'done.txt' to 'todo.txt'.
+TODO: 2 moved from 'tests/trash directory.t1850-move/done.txt' to 'tests/trash directory.t1850-move/todo.txt'.
*   ok 5: basic move with passed source 2
*   ok 6: basic move with passed source 3
* FAIL 7: move to destination without EOL 1
todo.sh -f move 2 todo.txt done.txt | sed "s#'[^']\+/\([^/']\+\)'#'\1'#g" 
--- expect	2020-03-27 18:37:30.000000000 +0000
+++ output	2020-03-27 18:37:30.000000000 +0000
@@ -1,2 +1,2 @@
 2 x 2009-02-13 smell the coffee +wakeup
-TODO: 2 moved from 'done.txt' to 'todo.txt'.
+TODO: 2 moved from 'tests/trash directory.t1850-move/done.txt' to 'tests/trash directory.t1850-move/todo.txt'.
*   ok 8: move to destination without EOL 2
*   ok 9: move to destination without EOL 3
* failed 3 among 9 test(s)
make: *** [tests/t1850-move.sh] Error 1

@karbassi
Copy link
Member

We have GitHub Actions now! 👍
The tests are failing. 👎

Copy link
Member

@karbassi karbassi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t1850-move fails on macOS

@inkarkat
Copy link
Member Author

@karbassi Thank you for setting up the new CI builds; that's really great! (And I involuntarily demonstrated why it's so important to have them.)

I've fixed the compatibility problem; fortunately, that was an easy one and I didn't have to update my FreeBSD VM to see how barren it is in non-GNU land :-)

@karbassi
Copy link
Member

@inkarkat looks good. Merge.

@karbassi karbassi merged commit 861ad5e into todotxt:master Mar 29, 2020
@inkarkat inkarkat deleted the fix/noeol branch March 30, 2020 08:42
@karbassi karbassi changed the title Fix/noeol Fix no end-of-line bug Aug 12, 2020
wwalker pushed a commit to wwalker/todo.txt-cli that referenced this pull request Sep 19, 2021
* Handle missing EOL in todo.txt

This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file.
In _addto(), ensure a trailing newline via sed (taken from https://unix.stackexchange.com/a/31955/18876).

Fixes todotxt#294

* Tests: Add basic coverage of move

* Handle missing EOL in todo.txt for move, too

This can happen easily with certain editors (such as Mousepad) that do not automatically add a newline character at the end of a file.

* Refactoring: Extract fixMissingEndOfLine()

* FIX: Compatibility: sed \+ multi not supported on MacOS

Use the POSIX \{1,\} instead.

Co-authored-by: Ali Karbassi <ali@karbassi.com>
bradyt pushed a commit to bradyt/todo.txt-cli that referenced this pull request Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add command does not check/add preceding newline character
2 participants