Browse Source

fix(win): Prevent exception on empty list

Add check for when an empty list remains after preprocessing and do
not continue for both legacy and modern windows implementations.

Fix #71
master
Andrew Senetar 8 months ago
parent
commit
4b9bc4bc31
Signed by: arsenetar
GPG Key ID: C63300DCE48AB2F1
  1. 3
      send2trash/win/legacy.py
  2. 2
      send2trash/win/modern.py
  3. 14
      tests/test_plat_win.py

3
send2trash/win/legacy.py

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
from __future__ import unicode_literals
import os.path as op
from send2trash.compat import text_type
from send2trash.util import preprocess_paths
@ -142,6 +143,8 @@ def get_short_path_name(long_name): @@ -142,6 +143,8 @@ def get_short_path_name(long_name):
def send2trash(paths):
paths = preprocess_paths(paths)
if not paths:
return
# convert data type
paths = [text_type(path, "mbcs") if not isinstance(path, text_type) else path for path in paths]
# convert to full paths

2
send2trash/win/modern.py

@ -17,6 +17,8 @@ from send2trash.win.IFileOperationProgressSink import create_sink @@ -17,6 +17,8 @@ from send2trash.win.IFileOperationProgressSink import create_sink
def send2trash(paths):
paths = preprocess_paths(paths)
if not paths:
return
# convert data type
paths = [text_type(path, "mbcs") if not isinstance(path, text_type) else path for path in paths]
# convert to full paths

14
tests/test_plat_win.py

@ -204,3 +204,17 @@ def test_trash_long_multifile_legacy(longfiles): @@ -204,3 +204,17 @@ def test_trash_long_multifile_legacy(longfiles):
# )
# def test_trash_long_folder_legacy(self):
# self._trash_folder(s2t_legacy)
def test_trash_nothing_legacy():
try:
s2t_legacy([])
except Exception as ex:
assert False, f"Exception thrown when trashing nothing: {ex}"
def test_trash_nothing_modern():
try:
s2t_modern([])
except Exception as ex:
assert False, f"Exception thrown when trashing nothing: {ex}"

Loading…
Cancel
Save