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

@ -8,7 +8,13 @@ import tempfile
import unittest
from .exceptions import CommandError
from .hooks import Hooks
from .utils import run_cmd_wait, run_cmd_wait_nofail, which, task_binary_location
from .utils import (
run_cmd_wait,
run_cmd_wait_nofail,
which,
task_binary_location,
CMAKE_BINARY_DIR,
)
from .compat import STRING_TYPE
@ -300,5 +306,21 @@ class Task(object):
# Use advanced time format
self._command = [cmd, "-f", faketime] + self._command
def make_tc_task(self, **props):
"""Create a task directly in TaskChampion, bypassing TaskWarrior
entirely, and returning the UUID. The properties are not interpreted by
the shell.
"""
# Generate the path to the `make_tc_task` binary, which is a dependency of the
# test runner.
make_tc_task = os.path.abspath(
os.path.join(CMAKE_BINARY_DIR, "test", "make_tc_task")
)
cmd = [make_tc_task, self.datadir]
for p, v in props.items():
cmd.append(f"{p}={v}")
_, out, _ = run_cmd_wait(cmd)
return out.strip()
# vim: ai sts=4 et sw=4