Trim whitespace from filename

This avoids an OSError when the book's metadata has whitespace at the end of it.
This commit is contained in:
Ryan Holmes 2020-08-09 01:08:00 -04:00 committed by GitHub
parent 1a1d105fae
commit 969105b205
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -254,7 +254,7 @@ def get_valid_filename(value, replace_whitespace=True):
value = re.sub(r'[\*\+:\\\"/<>\?]+', u'_', value, flags=re.U) value = re.sub(r'[\*\+:\\\"/<>\?]+', u'_', value, flags=re.U)
# pipe has to be replaced with comma # pipe has to be replaced with comma
value = re.sub(r'[\|]+', u',', value, flags=re.U) value = re.sub(r'[\|]+', u',', value, flags=re.U)
value = value[:128] value = value[:128].strip()
if not value: if not value:
raise ValueError("Filename cannot be empty") raise ValueError("Filename cannot be empty")
if sys.version_info.major == 3: if sys.version_info.major == 3: