Bug Fix: Issue 6 append and replace unexpected behavior if there's an & in task (even in quotes)
Using the cleaninput function, to escape &'s on certain actions. Currently the actions needing escaped &'s are append, prepend and replace. Other actions including add need unescaped &'s.
This commit is contained in:
@@ -55,4 +55,18 @@ TODO: 'smell the uppercase Roses' added on line 3.
|
|||||||
TODO: 2 of 3 tasks shown from $HOME/todo.txt
|
TODO: 2 of 3 tasks shown from $HOME/todo.txt
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'add with &' <<EOF
|
||||||
|
>>> todo.sh add "dig the garden & water the flowers"
|
||||||
|
TODO: 'dig the garden & water the flowers' added on line 4.
|
||||||
|
|
||||||
|
>>> todo.sh list
|
||||||
|
4 dig the garden & water the flowers
|
||||||
|
1 notice the daisies
|
||||||
|
2 smell the roses
|
||||||
|
3 smell the uppercase Roses
|
||||||
|
--
|
||||||
|
TODO: 4 of 4 tasks shown from $HOME/todo.txt
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|||||||
@@ -72,6 +72,12 @@ TODO: 4 prioritized (A).
|
|||||||
replaced with
|
replaced with
|
||||||
4: (A) collect the bread
|
4: (A) collect the bread
|
||||||
EOF
|
EOF
|
||||||
|
test_todo_session 'replace with &' << EOF
|
||||||
|
>>> todo.sh replace 3 "thrash the hay & thresh the wheat"
|
||||||
|
3: jump on hay
|
||||||
|
replaced with
|
||||||
|
3: thrash the hay & thresh the wheat
|
||||||
|
EOF
|
||||||
|
|
||||||
test_todo_session 'replace error' << EOF
|
test_todo_session 'replace error' << EOF
|
||||||
>>> todo.sh replace 10 "hej!"
|
>>> todo.sh replace 10 "hej!"
|
||||||
|
|||||||
@@ -52,4 +52,9 @@ TODO: 3 of 3 tasks shown from $HOME/todo.txt
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'prepend with &' <<EOF
|
||||||
|
>>> todo.sh prepend 3 "no running & jumping now"
|
||||||
|
3: no running & jumping now stop
|
||||||
|
EOF
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|||||||
47
tests/t1600-append.sh
Executable file
47
tests/t1600-append.sh
Executable file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='basic append functionality
|
||||||
|
|
||||||
|
Ensure we can append items successfully.
|
||||||
|
'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Set up the basic todo.txt
|
||||||
|
#
|
||||||
|
todo.sh add notice the daisies > /dev/null
|
||||||
|
|
||||||
|
test_todo_session 'append usage' <<EOF
|
||||||
|
>>> todo.sh append adf asdfa
|
||||||
|
=== 1
|
||||||
|
usage: todo.sh append ITEM# "TEXT TO APPEND"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'basic append' <<EOF
|
||||||
|
>>> todo.sh append 1 "smell the roses"
|
||||||
|
1: notice the daisies smell the roses
|
||||||
|
|
||||||
|
>>> todo.sh list
|
||||||
|
1 notice the daisies smell the roses
|
||||||
|
--
|
||||||
|
TODO: 1 of 1 tasks shown from $HOME/todo.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_todo_session 'basic append with &' <<EOF
|
||||||
|
>>> todo.sh append 1 "see the wasps & bees"
|
||||||
|
1: notice the daisies smell the roses see the wasps & bees
|
||||||
|
|
||||||
|
>>> todo.sh list
|
||||||
|
1 notice the daisies smell the roses see the wasps & bees
|
||||||
|
--
|
||||||
|
TODO: 1 of 1 tasks shown from $HOME/todo.txt
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
test_todo_session 'append error' << EOF
|
||||||
|
>>> todo.sh append 10 "hej!"
|
||||||
|
=== 1
|
||||||
|
10: No such todo.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_done
|
||||||
8
todo.sh
8
todo.sh
@@ -244,8 +244,14 @@ cleanup()
|
|||||||
cleaninput()
|
cleaninput()
|
||||||
{
|
{
|
||||||
# Cleanup the input
|
# Cleanup the input
|
||||||
# Replace newlines with spaces
|
# Replace newlines with spaces Always
|
||||||
input=`echo $input | tr -d '\r|\n'`
|
input=`echo $input | tr -d '\r|\n'`
|
||||||
|
|
||||||
|
# Check which action we are being used in as this affects what cleaning we do
|
||||||
|
if [[ $action =~ (append|app|prepend|prep|replace) ]]; then
|
||||||
|
# These actions use sed and & as the matched string so escape it
|
||||||
|
input=`echo $input | sed 's/\&/\\\&/g'`
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
archive()
|
archive()
|
||||||
|
|||||||
Reference in New Issue
Block a user