From 331086f27b19fefe0f3bc4df31226cd2359ed0ce Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 18 Apr 2021 14:47:51 -0400 Subject: [PATCH] [xmlreport] when a filepath is in multiple source dirs, choose the highest one fixes #578 --- coverage/xmlreport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py index 8c8409dc5..e14a19ea5 100644 --- a/coverage/xmlreport.py +++ b/coverage/xmlreport.py @@ -148,7 +148,7 @@ def xml_file(self, fr, analysis, has_arcs): # Create the 'lines' and 'package' XML elements, which # are populated later. Note that a package == a directory. filename = fr.filename.replace("\\", "/") - for source_path in self.source_paths: + for source_path in sorted(self.source_paths, key=len): source_path = files.canonical_filename(source_path) if filename.startswith(source_path.replace("\\", "/") + "/"): rel_name = filename[len(source_path)+1:]