ctaggart / SourceLink

Source Code On Demand
MIT License
356 stars 55 forks source link

sourcelink test does not match URLs correctly #386

Open tmat opened 5 years ago

tmat commented 5 years ago

This function does not handle multiple source link entries correctly: https://github.com/ctaggart/SourceLink/blob/master/dotnet-sourcelink/Program.cs#L477

Consider, for example, the following source link JSON:

{
  "documents":
  {
    "/_/*":"https://raw.githubusercontent.com/aspnet/AspNetCore/0049c5899ca78e8fef7d77b355b555b793bf6616/*",
    "/_/src/submodules/googletest/*":"https://raw.githubusercontent.com/google/googletest/4e4df226fc197c0dda6e37f5c8c3845ca1e73a49/*",
    "/_/src/submodules/MessagePack-CSharp/*":"https://raw.githubusercontent.com/aspnet/MessagePack-CSharp/8861abdde93a3b97180ac3b2eafa33459ad52392/*"
  }
}

and a document path in the PDB:

/_/src/submodules/MessagePack-CSharp/src/MessagePack/SequencePool.cs

This path should match the last pattern /_/src/submodules/MessagePack-CSharp/* but it matches the first one.

The longest matching patter should be used.

See https://github.com/dotnet/designs/blob/master/accepted/diagnostics/source-link.md:

Source Link JSON may contain multiple relative and/or absolute mappings in any order. They will be resolved in order from most specific to least specific. Here is an example of a valid Source Link JSON for an arbitrary project structure