Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash while removing file/dir wth utf-8 chars #332

Open
laluka opened this issue Jan 23, 2024 · 2 comments
Open

Crash while removing file/dir wth utf-8 chars #332

laluka opened this issue Jan 23, 2024 · 2 comments

Comments

@laluka
Copy link

laluka commented Jan 23, 2024

Describe the bug

Removing a file with specific utf 8 chars breaks trash-put (and probably others) ! 🙃

trash-cli version
Output of: trash-put --version
trash-put 0.17.1.14 up to 0.23.11.10

Are you using the latest version of trash-cli?
Yes

Have you tried if the bug is present in the latest version of trash-cli?
Yes

Have done that? Then continue with the bug report.

Operating system:

  • OS: Linux mothership 6.5.0-14-generic #14~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov 20 18:15:30 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

To Reproduce
Copy and paste the commands (and their output) to execute in order to reproduce
the behavior:

mkdir $(echo -ne "\xFF\x2E\xFF\x2E")
trash-put $'\377'.$'\377'.                 # RET CODE 130

# Same with
trash-put "$(echo -ne "\xFF\x2E\xFF\x2E")"

Traceback (most recent call last):
  File "/usr/bin/trash-put", line 5, in <module>
    sys.exit(main())
  File "/usr/lib/python3/dist-packages/trashcli/put.py", line 21, in main
    ).run(sys.argv)
  File "/usr/lib/python3/dist-packages/trashcli/put.py", line 68, in run
    trashcan.trash_all(args)
  File "/usr/lib/python3/dist-packages/trashcli/put.py", line 246, in trash_all
    self.trash(arg)
  File "/usr/lib/python3/dist-packages/trashcli/put.py", line 280, in trash
    trashed_file = trash_dir.trash(file)
  File "/usr/lib/python3/dist-packages/trashcli/put.py", line 399, in trash
    content = self.format_trashinfo(original_location, self.now())
  File "/usr/lib/python3/dist-packages/trashcli/put.py", line 427, in format_trashinfo
    "Path=%s\n" % format_original_location(original_location) +
  File "/usr/lib/python3/dist-packages/trashcli/put.py", line 425, in format_original_location
    return quote(original_location,'/')
  File "/usr/lib/python3.10/urllib/parse.py", line 875, in quote
    string = string.encode(encoding, errors)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 23: surrogates not allowed

Expected behavior
File/Dir being removed

Have a marvelous day, sorry for the crash :( 💟

@penthium2
Copy link

same bug on :
Linux 1fac59b8f594 6.6.12-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jan 16 01:35:44 UTC 2024 x86_64 GNU/Linux

@rennsax
Copy link

rennsax commented Feb 25, 2024

I met this problem when I use trash-list to show my trashes.

trash-put IMG_0023.JPG
trash-list

The error:

Traceback (most recent call last):
  File "/Users/renbaijun/.local/bin/trash-list", line 5, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/renbaijun/.local/share/pipx/venvs/trash-cli/lib/python3.12/site-packages/trashcli/list/main.py", line 41, in main
    ).run(sys.argv)
      ^^^^^^^^^^^^^
  File "/Users/renbaijun/.local/share/pipx/venvs/trash-cli/lib/python3.12/site-packages/trashcli/list/main.py", line 91, in run
    action.run_action(args)
  File "/Users/renbaijun/.local/share/pipx/venvs/trash-cli/lib/python3.12/site-packages/trashcli/list/list_trash_action.py", line 52, in run_action
    for message in ListTrash(self.environ,
  File "/Users/renbaijun/.local/share/pipx/venvs/trash-cli/lib/python3.12/site-packages/trashcli/list/list_trash_action.py", line 100, in list_all_trash
    for msg in self._print_trashinfo(volume, trash_info,
  File "/Users/renbaijun/.local/share/pipx/venvs/trash-cli/lib/python3.12/site-packages/trashcli/list/list_trash_action.py", line 120, in _print_trashinfo
    contents = self.content_reader.contents_of(trashinfo_path)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/renbaijun/.local/share/pipx/venvs/trash-cli/lib/python3.12/site-packages/trashcli/fs.py", line 123, in contents_of
    return _read_file(path)
           ^^^^^^^^^^^^^^^^
  File "/Users/renbaijun/.local/share/pipx/venvs/trash-cli/lib/python3.12/site-packages/trashcli/fs.py", line 243, in _read_file
    return f.read()
           ^^^^^^^^
  File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 37: invalid start byte

trash-restore also report the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants