Skip to content

Commit

Permalink
Merge pull request #23 from 0jonjo/22-tasks-not-created-when-use-punc…
Browse files Browse the repository at this point in the history
…tuation-and-special-characters

Add support to punctuation when create or edit tasks
  • Loading branch information
0jonjo authored Sep 1, 2024
2 parents 1a564ca + 0991587 commit d3adc40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ delete_line() {
}

edit_line() {
sed -i "${task}s/.*/- $new_task/" "$file.md"
escaped_task=$(sed 's/[\/&]/\\&/g' <<< "$new_task")
sed -i "${task}s/.*/- $escaped_task/" "$file.md"
echo "Line ${task} edited."
}

Expand Down
15 changes: 12 additions & 3 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,17 @@ if [ -z "$(sed -n "/# $mon/ p" "$file.md")" ]; then
fi
cd - > /dev/null

# Test edit command
output=$("$woche_script_path" edit 2 "New task")
# Test add task with punctituation to a day command
output=$("$woche_script_path" mon "Test task with punctuation: ;,!@#$%^&*()_+")
if [[ "$output" == *"Task 'Test task with punctuation: ;,!@#$%^&*()_+' added to"* ]]; then
echo "Test 'add task to a day' command: PASSED"
else
echo "Test 'add task to a day' command: FAILED"
fi
check_test_result

# Test edit command with punctituation
output=$("$woche_script_path" edit 2 "New task ,.!@")
if [[ "$output" == *"Line 2 edited."* ]]; then
echo "Test 'edit' command: PASSED"
else
Expand All @@ -138,7 +147,7 @@ fi

## Check if the task is edited on last test
cd "$path_to_files" > /dev/null
if [ -z "$(sed -n "2 p" "$file.md" | grep "New task")" ]; then
if [ -z "$(sed -n "2 p" "$file.md" | grep "New task ,.!@")" ]; then
echo "Error: Task has not been edited."
exit 1
fi
Expand Down
3 changes: 2 additions & 1 deletion woche.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ case $1 in
*)
file_exists
day=$(eval echo \$$1)
sed -i "/# $day/ a\\- $task" "$file.md"
escaped_task=$(sed 's/[\/&]/\\&/g' <<< "$task")
sed -i "/# $day/ a\\- $escaped_task" "$file.md"
echo "Task '$task' added to $day."
exit 0
;;
Expand Down

0 comments on commit d3adc40

Please sign in to comment.