From a97144d0e83674b65132272ea8d04e780b73e7b1 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Wed, 11 May 2011 16:12:03 +0200 Subject: [PATCH] FIX: cleaninput() for sed-replacement needs more escaping and unique separator. Commit 8e4364f5e1c559116370 removed the deletion of the "|" character from cleaninput. That was okay for the cleaninput() use in _addto(), but not in those cases that used $input for replacement via sed. Added corresponding tests for replace, append and prepend actions similar to what was added for the add action in the above commit. To really fix the problem (and not just remove all "|" characters from the text), a separator character must be found that is not part of $input, and this must be used in the sed expression. As cleaninput() already modifies the global $input variable, another $inputSep global variable is used to pass back this information. In addition, backslashes must be escaped in $input, or replacements like \1 wreak havoc. --- tests/t1100-replace.sh | 28 ++++++++++++++++++++++++---- tests/t1400-prepend.sh | 22 ++++++++++++++++++++++ tests/t1600-append.sh | 29 +++++++++++++++++++++++++---- todo.sh | 18 ++++++++++++++---- 4 files changed, 85 insertions(+), 12 deletions(-) diff --git a/tests/t1100-replace.sh b/tests/t1100-replace.sh index aa3f9ad..370446f 100755 --- a/tests/t1100-replace.sh +++ b/tests/t1100-replace.sh @@ -45,6 +45,12 @@ grow some corn thrash some hay chase the chickens EOF +test_todo_session 'replace error' << EOF +>>> todo.sh replace 10 "hej!" +=== 1 +TODO: No task 10. +EOF + test_todo_session 'replace in multi-item file' <>> todo.sh replace 1 smell the cheese 1 smell the cows @@ -89,10 +95,24 @@ grow some corn thrash some hay chase the chickens EOF -test_todo_session 'replace error' << EOF ->>> todo.sh replace 10 "hej!" -=== 1 -TODO: No task 10. +test_todo_session 'replace with symbols' <>> todo.sh replace 1 "~@#$%^&*()-_=+[{]}|;:',<.>/?" +1 smell the cows +TODO: Replaced task with: +1 ~@#$%^&*()-_=+[{]}|;:',<.>/? + +>>> todo.sh replace 2 '\`!\\"' +2 grow some corn +TODO: Replaced task with: +2 \`!\\" + +>>> todo.sh list +4 chase the chickens +3 thrash some hay +2 \`!\\" +1 ~@#$%^&*()-_=+[{]}|;:',<.>/? +-- +TODO: 4 of 4 tasks shown EOF cat /dev/null > todo.txt diff --git a/tests/t1400-prepend.sh b/tests/t1400-prepend.sh index e0cc049..5ddd925 100755 --- a/tests/t1400-prepend.sh +++ b/tests/t1400-prepend.sh @@ -57,6 +57,28 @@ test_todo_session 'prepend with &' < todo.txt <>> todo.sh prepend 1 "~@#$%^&*()-_=+[{]}|;:',<.>/?" +1 ~@#$%^&*()-_=+[{]}|;:',<.>/? smell the cows + +>>> todo.sh prepend 2 '\`!\\"' +2 \`!\\" grow some corn + +>>> todo.sh list +4 chase the chickens +3 thrash some hay +2 \`!\\" grow some corn +1 ~@#$%^&*()-_=+[{]}|;:',<.>/? smell the cows +-- +TODO: 4 of 4 tasks shown +EOF + cat /dev/null > todo.txt test_todo_session 'prepend handling prepended date on add' <>> todo.sh -t add "new task" diff --git a/tests/t1600-append.sh b/tests/t1600-append.sh index ed3e436..e75de78 100755 --- a/tests/t1600-append.sh +++ b/tests/t1600-append.sh @@ -17,6 +17,12 @@ test_todo_session 'append usage' <>> todo.sh append 10 "hej!" +=== 1 +TODO: No task 10. +EOF + test_todo_session 'basic append' <>> todo.sh append 1 "smell the roses" 1 notice the daisies smell the roses @@ -37,11 +43,26 @@ test_todo_session 'basic append with &' < todo.txt <>> todo.sh append 1 "~@#$%^&*()-_=+[{]}|;:',<.>/?" +1 smell the cows ~@#$%^&*()-_=+[{]}|;:',<.>/? -test_todo_session 'append error' << EOF ->>> todo.sh append 10 "hej!" -=== 1 -TODO: No task 10. +>>> todo.sh append 2 '\`!\\"' +2 grow some corn \`!\\" + +>>> todo.sh list +4 chase the chickens +2 grow some corn \`!\\" +1 smell the cows ~@#$%^&*()-_=+[{]}|;:',<.>/? +3 thrash some hay +-- +TODO: 4 of 4 tasks shown EOF cat > todo.txt <