summaryrefslogtreecommitdiff
path: root/coverage/xmlreport.py
diff options
context:
space:
mode:
authorKevin Brown-Silva <kevin-brown@users.noreply.github.com>2023-04-27 05:27:33 -0600
committerGitHub <noreply@github.com>2023-04-27 04:27:33 -0700
commitdf1bf082f242cccdcb342000525bede537b95935 (patch)
tree64c6f78a49bd0c124ff5c0ba3cb65df22f1ada08 /coverage/xmlreport.py
parent74b1758bb138355d5036631d8c92e7b0871339b2 (diff)
downloadpython-coveragepy-git-df1bf082f242cccdcb342000525bede537b95935.tar.gz
fix: source paths with trailing slashes causing inconsistent sources in XML report with relative_paths (#1608)
* Added failing test for source with trailing slash This test is nearly identical to the one above it, with the only change being the source that is used. This may end up turning into a fixture instead if the tests end up being identical after the fix is made. * Strip trailing slash for relative source paths This fixes an issue introduced in 45cf7936ee605cfe06f7f5967a72a73198960120 where using `relative_files=True` and `src` with a trailing slash, the source inserted as `<sources>` in the XML report would also have a trailing slash. This also fixes an issue introduced in the same commit where an empty `<source>` would be inserted as well for cases where the `src` has a trailing slash.
Diffstat (limited to 'coverage/xmlreport.py')
-rw-r--r--coverage/xmlreport.py2
1 files changed, 2 insertions, 0 deletions
diff --git a/coverage/xmlreport.py b/coverage/xmlreport.py
index 2c8fd0cc..b2180266 100644
--- a/coverage/xmlreport.py
+++ b/coverage/xmlreport.py
@@ -69,6 +69,8 @@ class XmlReporter:
if os.path.exists(src):
if not self.config.relative_files:
src = files.canonical_filename(src)
+ else:
+ src = src.rstrip(r"\/")
self.source_paths.add(src)
self.packages: Dict[str, PackageData] = {}
self.xml_out: xml.dom.minidom.Document