diff --git a/src/SourceLink.Tools.UnitTests/SourceLinkMapTests.cs b/src/SourceLink.Tools.UnitTests/SourceLinkMapTests.cs
index db134dfa..98c64a0b 100644
--- a/src/SourceLink.Tools.UnitTests/SourceLinkMapTests.cs
+++ b/src/SourceLink.Tools.UnitTests/SourceLinkMapTests.cs
@@ -66,12 +66,24 @@ public void Entries()
Assert.True(map.TryGetUri(@"C:\a", out var url));
Assert.Equal("http://server/[]", url);
+ Assert.True(map.TryGetUri(@"C:\a", out url, out var relativeFilePath));
+ Assert.Equal("http://server/[]", url);
+ Assert.Equal("", relativeFilePath);
+
Assert.True(map.TryGetUri(@"C:\a\b\c\d\e", out url));
Assert.Equal("http://server/[/b/c/d/e]", url);
+ Assert.True(map.TryGetUri(@"C:\a\b\c\d\e", out url, out relativeFilePath));
+ Assert.Equal("http://server/[/b/c/d/e]", url);
+ Assert.Equal(@"/b/c/d/e", relativeFilePath);
+
Assert.True(map.TryGetUri(@"C:\b", out url));
Assert.Equal("http://b", url);
+ Assert.True(map.TryGetUri(@"C:\b", out url, out relativeFilePath));
+ Assert.Equal("http://b", url);
+ Assert.Equal("b", relativeFilePath);
+
Assert.False(map.TryGetUri(@"C:\b\c", out _));
}
diff --git a/src/SourceLink.Tools/SourceLinkMap.cs b/src/SourceLink.Tools/SourceLinkMap.cs
index 2aff6b81..0f28b492 100644
--- a/src/SourceLink.Tools/SourceLinkMap.cs
+++ b/src/SourceLink.Tools/SourceLinkMap.cs
@@ -189,6 +189,24 @@ public bool TryGetUri(
[NotNullWhen(true)]
#endif
out string? uri)
+ {
+ return TryGetUri(path, out uri, out _);
+ }
+
+ ///
+ /// Maps specified to the corresponding URL.
+ ///
+ /// is null.
+ public bool TryGetUri(
+ string path,
+#if NETCOREAPP
+ [NotNullWhen(true)]
+#endif
+ out string? uri,
+#if NETCOREAPP
+ [NotNullWhen(true)]
+#endif
+ out string? relativeFilePath)
{
if (path == null)
{
@@ -198,6 +216,7 @@ public bool TryGetUri(
if (path.IndexOf('*') >= 0)
{
uri = null;
+ relativeFilePath = null;
return false;
}
@@ -209,20 +228,24 @@ public bool TryGetUri(
{
if (path.StartsWith(file.Path, StringComparison.OrdinalIgnoreCase))
{
- var escapedPath = string.Join("/", path.Substring(file.Path.Length).Split(new[] { '/', '\\' }).Select(Uri.EscapeDataString));
+ var relativePath = path.Substring(file.Path.Length).Replace('\\', '/');
+ var escapedPath = string.Join("/", relativePath.Split('/').Select(Uri.EscapeDataString));
uri = mappedUri.Prefix + escapedPath + mappedUri.Suffix;
+ relativeFilePath = relativePath;
return true;
}
}
else if (string.Equals(path, file.Path, StringComparison.OrdinalIgnoreCase))
{
Debug.Assert(mappedUri.Suffix.Length == 0);
+ relativeFilePath = Path.GetFileName(file.Path);
uri = mappedUri.Prefix;
return true;
}
}
uri = null;
+ relativeFilePath = null;
return false;
}
}