GothenburgBitFactory / GothenburgBitFactory/taskwarrior

Taskwarrior doesn't support `\uXXXX` sequences in tags when reading from hooks

Open
#2,744 0 comments 1 reaction 0 assignees View on GitHub
topic:encodings topic:hooks
Dominant language
C++
Stars
6.1k
Forks
423
Avg merge
1d 19h
Merged PRs (30d)
11

Description

When interacting with hooks, taskwarrior doesn't handle escape sequences in `tags` field.

But escape sequences are supported in `description` field. So I think this is a bug.

+ What command(s) did you run?

I was using a simplified hook script from [timewarrior](https://github.com/GothenburgBitFactory/timewarrior):

```python3
#!/usr/bin/python3

import json
import sys

lineold = sys.stdin.buffer.readline().decode("utf-8", errors="replace")
linenew = sys.stdin.buffer.readline().decode("utf-8", errors="replace")
new = json.loads(linenew)
print(json.dumps(new))
```

and ran these command below:

```sh
task add tags:🤔🤔🤔🤔 😋😋😋😋
task 1 start
task
```

+ What did you expect to happen?

I expect the tags remain readable:

shot1

+ What actually happened?

I got this:

shot0

+ Paste the output of the task diag command.

```plain
task 2.6.1
Platform: Linux

Compiler
Version: 11.2.0
Caps: +stdc +stdc_hosted +LP64 +c8 +i32 +l64 +vp64 +time_t64
Compliance: C++17

Build Features
Commit: e60fdafda
CMake: 3.22.1
libuuid: libuuid + uuid_unparse_lower
libgnutls: n/a
Build type:

Configuration
File: /home/jyi/.taskrc (found), 1562 bytes, mode 100644
Data: /home/jyi/.task (found), dir, mode 40755
Locking: Enabled
GC: Enabled
$EDITOR: vim
Server:
CA: -
Certificate: -
Key: -
Trust: strict
Ciphers: NORMAL
Creds:

Hooks
System: Enabled
Location: /home/jyi/.task/hooks
Active: on-modify.timewarrior (executable)
Inactive:

Tests
Terminal: 120x30
Dups: Scanned 20 tasks for duplicate UUIDs:
No duplicates found
Broken ref: Scanned 20 tasks for broken references:
No broken references found
```

I tried to add some print statement in the hook script, like:

```python3
#!/usr/bin/python3

import json
import sys

lineold = sys.stdin.buffer.readline().decode("utf-8", errors="replace")
linenew = sys.stdin.buffer.readline().decode("utf-8", errors="replace")
print("raw =", linenew, file=sys.stderr)
new = json.loads(linenew)
print(json.dumps(new))
print("dump =", json.dumps(new), file=sys.stderr)
```

and then run

```sh
task add tags:🤔🤔🤔🤔 😋😋😋😋
task 1 start
cat ~/.task/pending.data
```

then I got this output:

```plain
Created task 1.
raw = {"description":"😋😋😋😋","entry":"20220309T024947Z","modified":"20220309T024947Z","start":"20220309T024947Z","status":"pending","uuid":"74adece9-dc11-4efd-9b51-e161d8670ba3","tags":["🤔🤔🤔🤔"]}

dump = {"description": "\ud83d\ude0b\ud83d\ude0b\ud83d\ude0b\ud83d\ude0b", "entry": "20220309T024947Z", "modified": "20220309T024947Z", "start": "20220309T024947Z", "status": "pending", "uuid": "74adece9-dc11-4efd-9b51-e161d8670ba3", "tags": ["\ud83e\udd14\ud83e\udd14\ud83e\udd14\ud83e\udd14"]}
Starting task 74adece9 '����������������'.
Started 1 task.
[description:"����������������" entry:"1646794187" modified:"1646794187" start:"1646794187" status:"pending" tags:"\\ud83e\\udd14\\ud83e\\udd14\\ud83e\\udd14\\ud83e\\udd14" tags_\ud83e\udd14\ud83e\udd14\ud83e\udd14\ud83e\udd14:"x" uuid:"74adece9-dc11-4efd-9b51-e161d8670ba3"]
```

It seems that the script printed tags with `\uXXXX` escape sequence, and taskwarrior didn't unescape these sequences but have them escaped again. And then the tag became unreadable.

I guess that support escape sequences in tags may solve this problem.

Thaks in advance for your help.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the on-modify.timewarrior hook and the task add/start commands shown, then inspect how hook JSON is read and written before the data reaches ~/.task/pending.data. Done means Unicode tags remain readable after the hook round trip, matching the behavior already observed for descriptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.