Skip to content

Commit 13c2e2b

Browse files
authored
Merge pull request #437 from MarcoRossignoli/fixsourcelinkbug
[Bug fix]Fix "/p:UseSourceLink=true" bug
2 parents 1cbeee8 + 28765d9 commit 13c2e2b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/coverlet.core/Coverage.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,18 @@ private string GetSourceLinkUrl(Dictionary<string, string> sourceLinkDocuments,
339339
string key = sourceLinkDocument.Key;
340340
if (Path.GetFileName(key) != "*") continue;
341341

342-
if (!Path.GetDirectoryName(document).StartsWith(Path.GetDirectoryName(key) + Path.DirectorySeparatorChar))
343-
continue;
342+
string directoryDocument = Path.GetDirectoryName(document);
343+
string sourceLinkRoot = Path.GetDirectoryName(key);
344+
string relativePath = "";
345+
346+
// if document is on repo root we skip relative path calculation
347+
if (directoryDocument != sourceLinkRoot)
348+
{
349+
if (!directoryDocument.StartsWith(sourceLinkRoot + Path.DirectorySeparatorChar))
350+
continue;
344351

345-
var relativePath = Path.GetDirectoryName(document).Substring(Path.GetDirectoryName(key).Length + 1);
352+
relativePath = directoryDocument.Substring(sourceLinkRoot.Length + 1);
353+
}
346354

347355
if (relativePathOfBestMatch.Length == 0)
348356
{

0 commit comments

Comments
 (0)