taskwarrior icon indicating copy to clipboard operation
taskwarrior copied to clipboard

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

Open jyi2ya opened this issue 3 years ago • 0 comments

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:

#!/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:

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.
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:

#!/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

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

then I got this output:

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.

jyi2ya avatar Mar 09 '22 03:03 jyi2ya