Removing newlines from file titles.

This commit is contained in:
Roland 2023-05-15 09:28:00 -06:00
parent 7c5caf1dfd
commit 7de8275942
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 7 additions and 2 deletions

View file

@ -774,12 +774,12 @@ def get_files_and_directories(directory: Path):
# These characters are invalid in Windows or Linux.
INVALID_FILE_CHARS = re.compile(r'[/<>:\|"\\\?\*%!]')
INVALID_FILE_CHARS = re.compile(r'[/<>:\|"\\\?\*%!\n\r]')
def escape_file_name(name: str) -> str:
"""Remove any invalid characters in a file name."""
return INVALID_FILE_CHARS.sub('', name)
return INVALID_FILE_CHARS.sub('', name).strip()
def native_only(func: callable):

View file

@ -284,6 +284,11 @@ def test_zig_zag(low, high, expected):
('foo&', 'foo&'),
('foo%', 'foo'),
('foo!', 'foo'),
('fo\no', 'foo'),
('fo\ro', 'foo'),
('foo\r', 'foo'),
('foo\r', 'foo'),
('foo ', 'foo'),
]
)
def test_escape_file_name(name, expected):