Skip to content

Commit d3adc40

Browse files
authored
Merge pull request #23 from 0jonjo/22-tasks-not-created-when-use-punctuation-and-special-characters
Add support to punctuation when create or edit tasks
2 parents 1a564ca + 0991587 commit d3adc40

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

functions.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ delete_line() {
5353
}
5454

5555
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"
5758
echo "Line ${task} edited."
5859
}
5960

tests.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,17 @@ if [ -z "$(sed -n "/# $mon/ p" "$file.md")" ]; then
128128
fi
129129
cd - > /dev/null
130130

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 ,.!@")
133142
if [[ "$output" == *"Line 2 edited."* ]]; then
134143
echo "Test 'edit' command: PASSED"
135144
else
@@ -138,7 +147,7 @@ fi
138147

139148
## Check if the task is edited on last test
140149
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
142151
echo "Error: Task has not been edited."
143152
exit 1
144153
fi

woche.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ case $1 in
6161
*)
6262
file_exists
6363
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"
6566
echo "Task '$task' added to $day."
6667
exit 0
6768
;;

0 commit comments

Comments
 (0)