diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2018-01-20 10:01:28 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2018-01-20 10:01:28 -0500 |
commit | 46b123e14ba35db22282c124337b21e8d10f480f (patch) | |
tree | 42ec71f00bd78cdee9a2589f0332b96c49be5180 /coverage/files.py | |
parent | e5f0d09a969ec9124e5fc7a9a82aa97cffc2afbb (diff) | |
download | python-coveragepy-git-46b123e14ba35db22282c124337b21e8d10f480f.tar.gz |
Don't ever create HTML filenames longer than ~200 chars. Fixes #627.
Diffstat (limited to 'coverage/files.py')
-rw-r--r-- | coverage/files.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/coverage/files.py b/coverage/files.py index 04ce9cb1..12b89e8f 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -3,6 +3,7 @@ """File wrangling.""" +import hashlib import fnmatch import ntpath import os @@ -75,6 +76,9 @@ def canonical_filename(filename): return CANONICAL_FILENAME_CACHE[filename] +MAX_FLAT = 200 + +@contract(filename='unicode', returns='unicode') def flat_rootname(filename): """A base for a flat file name to correspond to this file. @@ -86,7 +90,11 @@ def flat_rootname(filename): """ name = ntpath.splitdrive(filename)[1] - return re.sub(r"[\\/.:]", "_", name) + name = re.sub(r"[\\/.:]", "_", name) + if len(name) > MAX_FLAT: + h = hashlib.sha1(name.encode('UTF-8')).hexdigest() + name = name[-(MAX_FLAT-len(h)-1):] + '_' + h + return name if env.WINDOWS: |