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 | e6b23c689a7c5b08131aff1962cccf8a93c50f3c (patch) | |
tree | 89d3df8bee3ddde81923cc63f3bb59a29eec5967 /coverage/files.py | |
parent | 2e3428fa02082c982409b1bf8db1bb9523aac7f4 (diff) | |
download | python-coveragepy-e6b23c689a7c5b08131aff1962cccf8a93c50f3c.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 04ce9cb..12b89e8 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: |