Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

link text containing backtick code doesn't work for []::() #1209

Closed

Description

@ericseppanen

With Markdown 3.3.6, the following markdown link doesn't render properly (no output is generated):

[Hello `[T]::world()` link](https://example.com)

If I remove the inner right-bracket ] or the following colon :, or the open parenthesis (, then it does render something.

commonmark 0.9.1 is able to render this link as expected:

<a href="https://example.com">Hello <code>[T]::world()</code> link</a>

Activity

  1. facelessuser commented on Jan 9, 2022

    @facelessuser
    Collaborator
  2. ericseppanen commented on Jan 9, 2022

    @ericseppanen
    Author

    I found a bunch of examples of this bug in the "This Week in Rust" repository, which has a lot of unordered lists containing only links, so the link is the only thing in the enclosing tag (an <li>).

  3. ericseppanen commented on Jan 9, 2022

    @ericseppanen
    Author

    I noticed another example, where there are no parentheses:

    • broken: [Hello `[T]::world`](https://example.com)
    • works: [Hello `[T]::world `](https://example.com) (note space before closing backtick)
  4. facelessuser commented on Jan 9, 2022

    @facelessuser
    Collaborator

    This is a weird issue for sure, and I doubt it is something as simple as the link pattern needs improvement because it does work, depending on unrelated context. I suspect that something else is causing the content to get dropped, but it will require a deep dive to debug what is going on.

  5. facelessuser commented on Jan 9, 2022

    @facelessuser
    Collaborator

    Well, I know what is causing the issue now, I'm just not sure how to fix it yet. The block processor called ReferenceProcessor is responsible for swallowing this content before the link processor even has a chance.

    I'll have to try and figure out how we can work around this. I probably won't have a solution this weekend, but this is a good starting point as we now have a root cause.

  6. added
    bug
    confirmed
    on Jan 9, 2022
  7. waylan commented on Jan 10, 2022

    @waylan
    Member

    This is a very specific edge case which requires the internal square brackets, the colon and (optionally) the internal parentheses. Without any one of those specific characters in that specific order, this would not be an issue. For the record, the example ([Hello `[T]::world()` link](https://example.com)) gets parsed into these parts:

    Reference: [Hello `[T]:
    URL: :world
    Title: ()` link](https://example.com)
    

    And the second example ([Hello `[T]::world`](https://example.com)) into these parts:

    Reference: [Hello `[T]:
    URL: :world`](https://example.com)
    

    I should note that between the square brackets of the reference we do not allow a closing square bracket (regex: \[([^\]]*)\]:). If this is correct (needs verification), then we should simply not allow either opening or closing square brackets (\[([^\[\]]*)\]:), which would be an easy fix.

    However, if it is wrong to exclude nested square brackets from references, then I see a few possible workarounds:

    1. Make it backtick aware. It should ignore anything between backtick pairs within the reference.
    2. Make it nested bracket aware. It should recognize that a closing bracket is closing the child opening bracket, not the parent bracket.
    3. Only match valid URLs as URLs (we currently only match any non-whitespace characters).

    Any of those solutions would drastically complicate the regex we use and/or require us to not use a single regex for the entire match.

  8. waylan commented on Jan 10, 2022

    @waylan
    Member

    Whether square brackets are allowed within references seems to be mixed (see Babelmark).

    I find the strangest result to be the reference implementation (markdown.pl) which does not recognize the link as pointing to the reference, but it does recognize the reference and remove it from the document. It is clear that there is a bug there, but is the bug with the link or the reference? It is impossible to say for sure.

    Also of interest is the large number of implementations which error out with this very simple input. It seems that for the most part it is not expected that square brackets be nested inside references. The few implementations which do support it are the ones which already have the reputation of being more forgiving that average. Therefore, I am comfortable excluding the opening square bracket. We already disallow the closing square bracket anyway, so this is consistent with our existing behavior.

  9. ericseppanen commented on Jan 10, 2022

    @ericseppanen
    Author

    I'm not sure if This Week in Rust is an extreme outlier, but we use code backticks inside link text quite a lot (which often includes square brackets and other interesting characters), and it looks like we've been using them (mostly) successfully since about 2013.

    Today, it works about 99% of the time (because ]: is somewhat rare.) Removing support for [] entirely would have a pretty significant effect on our website & newsletter workflow.

    If we're going to be collateral damage, then I guess that's the way it goes, but I hope you understand that this would be a significant breaking change for us.

  10. facelessuser commented on Jan 10, 2022

    @facelessuser
    Collaborator

    Today, it works about 99% of the time (because ]: is somewhat rare.) Removing support for [] entirely would have a pretty significant effect on our website & newsletter workflow.

    I think you are misunderstanding. The change would apply to the reference pattern, not the link pattern.

    • References: [id]: link
    • LInk: [content](link)

    We would restrict brackets in the id within references.

  11. ericseppanen commented on Jan 10, 2022

    @ericseppanen
    Author

    I think you are misunderstanding. The change would apply to the reference pattern, not the link pattern.

    Ah, thank you for the clarification! Sorry for my misunderstanding.

  12. waylan commented on Jan 10, 2022

    @waylan
    Member

    The change would apply to the reference pattern, not the link pattern.

    Yes, that is correct. Of note is the fact that reference ids should generally be rather plain. While we do support the shortcut where the id is the link label ([label]) we also support the full syntax ([label][id]), which can be used when a label is more complex. Therefore, we don't loose any functionality with this restriction. In case it's not clear, I'm speaking of the syntax of the link in the document body which would point to a reference.

  13. added a commit that references this issue on Jan 10, 2022
    b7c1c1a
  14. added a commit that references this issue on Jan 10, 2022
    af38c42
  15. ericseppanen commented on Jan 10, 2022

    @ericseppanen
    Author

    I verified that the committed fix works on all of the problematic examples in the TWiR repository.

    Thank you!

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

    bugconfirmed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions