File tree Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,8 @@ delete_line() {
53
53
}
54
54
55
55
edit_line () {
56
- sed -i " ${task} s/.*/- $new_task /" " $file .md"
56
+ escaped_task=$( sed ' s/[\/&]/\\&/g' <<< " $new_task" )
57
+ sed -i " ${task} s/.*/- $escaped_task /" " $file .md"
57
58
echo " Line ${task} edited."
58
59
}
59
60
Original file line number Diff line number Diff line change @@ -128,8 +128,17 @@ if [ -z "$(sed -n "/# $mon/ p" "$file.md")" ]; then
128
128
fi
129
129
cd - > /dev/null
130
130
131
- # Test edit command
132
- output=$( " $woche_script_path " edit 2 " New task" )
131
+ # Test add task with punctituation to a day command
132
+ output=$( " $woche_script_path " mon " Test task with punctuation: ;,!@#$%^&*()_+" )
133
+ if [[ " $output " == * " Task 'Test task with punctuation: ;,!@#$%^&*()_+' added to" * ]]; then
134
+ echo " Test 'add task to a day' command: PASSED"
135
+ else
136
+ echo " Test 'add task to a day' command: FAILED"
137
+ fi
138
+ check_test_result
139
+
140
+ # Test edit command with punctituation
141
+ output=$( " $woche_script_path " edit 2 " New task ,.!@" )
133
142
if [[ " $output " == * " Line 2 edited." * ]]; then
134
143
echo " Test 'edit' command: PASSED"
135
144
else
138
147
139
148
# # Check if the task is edited on last test
140
149
cd " $path_to_files " > /dev/null
141
- if [ -z " $( sed -n " 2 p" " $file .md" | grep " New task" ) " ]; then
150
+ if [ -z " $( sed -n " 2 p" " $file .md" | grep " New task ,.!@ " ) " ]; then
142
151
echo " Error: Task has not been edited."
143
152
exit 1
144
153
fi
Original file line number Diff line number Diff line change @@ -61,7 +61,8 @@ case $1 in
61
61
* )
62
62
file_exists
63
63
day=$( eval echo \$ $1 )
64
- sed -i " /# $day / a\\ - $task " " $file .md"
64
+ escaped_task=$( sed ' s/[\/&]/\\&/g' <<< " $task" )
65
+ sed -i " /# $day / a\\ - $escaped_task " " $file .md"
65
66
echo " Task '$task ' added to $day ."
66
67
exit 0
67
68
;;
You can’t perform that action at this time.
0 commit comments