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

Explicitly encode path as UTF-8 in truncate_filename() #319

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions whipper/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ class MissingFrames(Exception):
def truncate_filename(path):
"""
Truncate filename to the max. len. allowed by the path's filesystem
Hopefully it handles Unicode strings correctly
"""
p, f = os.path.split(os.path.normpath(path))
f, e = os.path.splitext(f)
fn_lim = os.pathconf(p, 'PC_NAME_MAX') # max.filename length in bytes
# Get the filename length limit in bytes
fn_lim = os.pathconf(p.encode('utf-8'), 'PC_NAME_MAX')
f_max = fn_lim - len(e.encode('utf-8'))
f = unicodedata.normalize('NFC', f)
f_trunc = unicode(f.encode('utf-8')[:f_max], 'utf-8', errors='ignore')
Expand Down