GothenburgBitFactory / GothenburgBitFactory/taskwarrior
the Taskwarrior hook examples should use double quotes when emitting JSON
- Dominant language
- C++
- Stars
- 6.1k
- Forks
- 423
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 11
Description
Here's a partial snippet from the `on-modify` example hook provided by Taskwarrior itself.
```
...
...
# Output:
# - JSON, modified or unmodified.
# - Optional feedback/error.
echo $modified_task
echo 'on-modify'
...
...
```
Instead of `echo $modified_task`, it should use **`echo "$modified_task"`**
**Why:** because otherwise all kinds of undesirable things may occur, like losing multiple spaces (they would be compressed to a single space by the shell). Even **shell expansion** can occur if the task contains one or more * characters (asterisks). For example, a task with `hello * world` as its description could be expanded
to `hello world`.
Of course the hook scripts provided by Taskwarrior are just examples, but this is an easy and small improvement, providing a solid foundation upon which to build hooks without such errors.
The following Taskwarrior hook examples are affected (output format: filename:line_number:content):
**Original:**
```
on-add:13:echo $new_task
on-add.the:5:if (echo $new_task | grep -qE '[tT]eh');
on-add.the:7: new_task=$(echo $new_task | sed -r 's/([tT])eh/\1he/g')
on-add.the:11:echo $new_task
on-exit.shadow-file:30: echo Could not create $SHADOW_FILE
on-exit.shadow-file:34:echo Shadow file $SHADOW_FILE updated.
on-modify:15:echo $modified_task
```
**Fixed:**
```
on-add:13:echo "$new_task"
on-add.the:5:if (echo "$new_task" | grep -qE '[tT]eh');
on-add.the:7: new_task=$(echo "$new_task" | sed -r 's/([tT])eh/\1he/g')
on-add.the:11:echo "$new_task"
on-exit.shadow-file:30: echo "Could not create $SHADOW_FILE"
on-exit.shadow-file:34:echo "Shadow file $SHADOW_FILE updated."
on-modify:15:echo "$modified_task"
```
Contributor guide
Assessment
This issue has not been assessed yet.