Fix and test handling of backslashes in hooks (#3909)

* Update hooks to use `read -r` and `printf`

This portably avoids any interpretation of backslash escapes by the
shell.

* Support running make_tc_task elsewhere

* Add a test for backslashes in task descriptions
This commit is contained in:
Dustin J. Mitchell 2025-07-08 02:40:34 -04:00 committed by GitHub
parent 7fdcdebd19
commit c639cc030d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 115 additions and 75 deletions

View file

@ -5,12 +5,12 @@
# Input:
# - Line of JSON for proposed new task.
read new_task
read -r new_task
# Output:
# - JSON, modified or unmodified.
# - Optional feedback/error.
echo $new_task
printf "%s\n" "$new_task"
echo 'FEEDBACK'
# Status:

View file

@ -5,7 +5,7 @@
# Input:
# - Line of JSON for proposed new task.
read new_task
read -r new_task
# Output:
# - JSON, modified or unmodified.

View file

@ -5,12 +5,12 @@
# Input:
# - Line of JSON for proposed new task.
read new_task
read -r new_task
# Output:
# - JSON, modified or unmodified.
# - Optional feedback/error.
echo $new_task
printf "%s\n" "$new_task"
echo '{"description":"extra","status":"pending"}'
echo 'FEEDBACK'

View file

@ -5,7 +5,7 @@
# Input:
# - Line of JSON for proposed new task.
read new_task
read -r new_task
# Output:
# - JSON, modified or unmodified.

View file

@ -5,7 +5,7 @@
# Input:
# - Line of JSON for proposed new task.
read new_task
read -r new_task
# Output:
# - JSON, modified or unmodified.

View file

@ -5,7 +5,7 @@
# Input:
# - Line of JSON for proposed new task.
read new_task
read -r new_task
# Output:
# - JSON, modified or unmodified.

View file

@ -2,17 +2,17 @@
# Input:
# - Line of JSON for proposed new task.
read new_task
read -r new_task
if (echo $new_task | grep -qE '[tT]eh');
if (printf "%s\n" "$new_task" | grep -qE '[tT]eh');
then
new_task=$(echo $new_task | sed -r 's/([tT])eh/\1he/g')
new_task=$(printf "%s\n" "$new_task" | sed -r 's/([tT])eh/\1he/g')
fi
# Output:
# - JSON, modified
# - Optional feedback/error.
echo $new_task
printf "%s\n" "$new_task"
echo 'FEEDBACK'
# Status:

View file

@ -5,12 +5,12 @@
# Input:
# - Line of JSON for proposed new task.
read new_task
read -r new_task
# Output:
# - JSON, modified or unmodified.
# - Optional feedback/error.
echo $new_task
printf "%s\n" "$new_task"
echo 'FEEDBACK'
# Status:

View file

@ -2,9 +2,9 @@
echo "on-add executed"
while read TASK; do
while read -r TASK; do
echo "New task $TASK"
echo $TASK
printf "%s\n" "$TASK"
done
exit 0

View file

@ -5,7 +5,7 @@
# Input:
# - Read-only line of JSON for each task added/modified
while read modified_task
while read -r modified_task
do
echo 'CHANGED TASK'
done

View file

@ -5,7 +5,7 @@
# Input:
# - Read-only line of JSON for each task added/modified
while read modified_task
while read -r modified_task
do
echo 'CHANGED TASK'
done

View file

@ -2,7 +2,7 @@
echo "on-exit executed"
while read TASK; do
while read -r TASK; do
echo "New/modified task $TASK"
done

View file

@ -6,13 +6,13 @@
# Input:
# - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification
read original_task
read modified_task
read -r original_task
read -r modified_task
# Output:
# - JSON, modified or unmodified.
# - Optional feedback/error.
echo $modified_task
printf "%s\n" "$modified_task"
echo 'FEEDBACK'
# Status:

View file

@ -6,8 +6,8 @@
# Input:
# - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification
read original_task
read modified_task
read -r original_task
read -r modified_task
# Output:
# - JSON, modified or unmodified.

View file

@ -6,13 +6,13 @@
# Input:
# - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification
read original_task
read modified_task
read -r original_task
read -r modified_task
# Output:
# - JSON, modified or unmodified.
# - Optional feedback/error.
echo $modified_task
printf "%s\n" "$modified_task"
echo '{"description":"extra","status":"pending"}'
echo 'FEEDBACK'

View file

@ -6,8 +6,8 @@
# Input:
# - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification
read original_task
read modified_task
read -r original_task
read -r modified_task
# Output:
# - JSON, modified or unmodified.

View file

@ -6,8 +6,8 @@
# Input:
# - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification
read original_task
read modified_task
read -r original_task
read -r modified_task
# Output:
# - JSON, modified or unmodified.

View file

@ -6,8 +6,8 @@
# Input:
# - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification
read original_task
read modified_task
read -r original_task
read -r modified_task
# Output:
# - JSON, modified or unmodified.

View file

@ -6,13 +6,13 @@
# Input:
# - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification
read original_task
read modified_task
read -r original_task
read -r modified_task
# Output:
# - JSON, modified or unmodified.
# - Optional feedback/error.
echo $modified_task
printf "%s\n" "$modified_task"
echo 'FEEDBACK'
# Status:

View file

@ -6,13 +6,13 @@
# Input:
# - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification
read original_task
read modified_task
read -r original_task
read -r modified_task
# Output:
# - JSON, modified or unmodified.
# - Optional feedback/error.
echo $original_task
printf "%s\n" "$original_task"
# Status:
# - 0: JSON accepted, non-JSON is feedback.

View file

@ -2,9 +2,10 @@
echo "on-modify executed"
while read TASK MODTASK; do
echo "Existing task $TASK modified to $MODTASK"
echo $MODTASK
done
read -r TASK
read -r MODTASK
echo "Existing task $TASK modified to $MODTASK"
printf "%s\n" "$MODTASK"
exit 0