From e6b23c689a7c5b08131aff1962cccf8a93c50f3c Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 20 Jan 2018 10:01:28 -0500 Subject: Don't ever create HTML filenames longer than ~200 chars. Fixes #627. --- coverage/files.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'coverage/files.py') 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: -- cgit v1.2.1