Skip to content

Some xrefs for generics produce invalid triple slash comments #66

Closed

Description

@jeffhandley

The System.Buffers and System.Memory areas of dotnet/runtime have XML docs containing <xref> elements for generic types that have the "`" characters escaped as "%60", and this escaped format is being ported into triple slash comments, but the escaped format is invalid.

Example: System.Buffers.IPinnable ends up with the following:

    /// <summary>Provides a mechanism for pinning and unpinning objects to prevent the garbage collector from moving them.</summary>
    /// <remarks>The <xref:System.Buffers.MemoryManager%601> class implements the `IPinnable` interface.</remarks>
    public interface IPinnable

The expected result is:

    /// <summary>Provides a mechanism for pinning and unpinning objects to prevent the garbage collector from moving them.</summary>
    /// <remarks>The <see cref="System.Buffers.MemoryManager{T}" /> class implements the `IPinnable` interface.</remarks>
    public interface IPinnable

Activity

  1. jeffhandley commented on Mar 31, 2021

    @jeffhandley
    MemberAuthor

    @carlossanlop Feel free to assign this to me. I have a fix in the works that seems to be working...

    @@ -102,7 +102,7 @@ namespace Libraries.RoslynTripleSlash
     
             private static readonly string[] MarkdownHeaders = new[] { "[!NOTE]", "[!IMPORTANT]", "[!TIP]" };
     
    -        private static readonly string ValidRegexChars = @"A-Za-z0-9\-\._~:\/#\[\]\{\}@!\$&'\(\)\*\+,;`";
    +        private static readonly string ValidRegexChars = @"A-Za-z0-9\-\._~:\/#\[\]\{\}@!\$&'\(\)\*\+,;`\%";
             private static readonly string ValidExtraChars = @"\?=";
     
             private static readonly string RegexDocIdPattern = @"(?<prefix>[A-Za-z]{1}:)?(?<docId>[" + ValidRegexChars + @"]+)(?<overload>%2[aA])?(?<extraVars>\?[" + ValidRegexChars + @"]+=[" + ValidRegexChars + @"]+)?";
    @@ -975,6 +975,7 @@ namespace Libraries.RoslynTripleSlash
                 string docId = m.Groups["docId"].Value;
                 string overload = string.IsNullOrWhiteSpace(m.Groups["overload"].Value) ? "" : "O:";
                 docId = ReplacePrimitives(docId);
    +            docId = Regex.Replace(docId, @"%60", "`");
                 docId = Regex.Replace(docId, @"`\d", "{T}");
                 return overload + docId;
             }

    This allows the xref to match the regex to get recognized as one that needs to potentially be cleaned up, and then the "%60" gets replaced with "`" within the docId, and then the existing logic picks up for replacing "`1" with the "{T}" typeparam syntax. The result is then:

        /// <summary>Provides a mechanism for pinning and unpinning objects to prevent the garbage collector from moving them.</summary>
        /// <remarks>The <see cref="System.Buffers.MemoryManager{T}" /> class implements the `IPinnable` interface.</remarks>
        public interface IPinnable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions