镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Parse complicated url problem #366

Closed

Description

@lufeihaidao

In github, [Ajax](http://en.wikipedia.org/wiki/Ajax_(programming)) will be correctly parsed: Ajax, but marked will add unnecessary )

Activity

  1. chjj commented on Apr 28, 2014

    @chjj
    Member

    Marked follows original mardown.pl behavior for this. Libupskirt/sundown also shares the same behavior.

    If we're supposed to allow parentheses in urls, what happens when parentheses are incorrectly closed?

    [foo](http://example.com/foo_)bar)

    What should happen here? The only way to parse () is by keeping state and track of how many levels deep of nested parentheses you're in, but there are no rules for URLs. URLs might provide misnested parens, etc.

    What about:

    [foo](http://example.com/foo_(bar)

    Should marked keep parsing the text after "bar)" since it hasn't seen a proper closing paren for the link syntax?

    How about this:

    [foo](http://example.com/foo_(((((((((bar))

    Is marked even supposed to guess what is going on there by interpreting the parens in that url?

    I feel like this change would only exist to accommodate wikipedia links, which can already either be encoded, or included as link references.

    If someone can come up with a definite outline of what should happen in all these other cases, I'm all for it.

  2. dedalozzo commented on Apr 28, 2014

    @dedalozzo

    I got your point. Since you must have a line break, or a space after an url, or another url, or still you have reached the end of the document, you can simply consider the last parenthesis, like the parenthesis that closes the link.

    [foo](http://example.com/foo_(bar)
    

    In the above example, you should have the following link: http://example.com/foo_(bar. Using this approach every wikipedia link just works as is. You just consider the open and the close round brackets, ignoring all the others inside the link. I'm gonna post this bug in Hoedown too, Sundown is a dead project.

  3. JCMais commented on Apr 28, 2014

    @JCMais

    I just saw this while reading the source code from hoedown, https://github.com/hoedown/hoedown/blob/master/src/autolink.c#L102

    It's from the autolink feature, but somewhat related, isn't?

  4. dedalozzo commented on Apr 28, 2014

    @dedalozzo

    I have just known that the bug was fixed in Hoedown long time ago. Yeah, I suppose you right.

  5. scottgonzalez commented on May 5, 2014

    @scottgonzalez
    Contributor

    I got your point. Since you must have a line break, or a space after an url, or another url, or still you have reached the end of the document, you can simply consider the last parenthesis, like the parenthesis that closes the link.

    That would break links at the end of a parenthetical, which is common enough to be concerning.

  6. Ernest0x commented on May 15, 2014

    @Ernest0x

    Perhaps you could also support using double quotes inside the parenthesis and take everything inside the quotes as the url:

    [foo]("http://example.com/foo_(bar")
    
  7. scottgonzalez commented on May 15, 2014

    @scottgonzalez
    Contributor

    @chjj I think it's time to close this and just tell people to manually encode the URLs using %29 instead of ).

  8. scottgonzalez commented on May 15, 2014

    @scottgonzalez
    Contributor

    Actually, you'll need to implement paren matching logic for GFM. It looks like GitHub always requires paired parens inside a URL.

  9. chjj commented on May 15, 2014

    @chjj
    Member

    @scottgonzalez, I've told people that before. It doesn't seem very effective. This is probably the second issue on this. GFM does do it, and I think it's unintelligent, but I'll try it and see how it goes. Maybe it won't hurt performance much and I'll be okay with it despite disagreeing with it philosophically.

  10. dedalozzo commented on May 15, 2014

    @dedalozzo

    You can't ask people to encode urls, because they simply copy and paste urls from the address bar of a browser. :-(

    -Filippo

    On May 15, 2014, at 2:19 PM, Scott González wrote:

    @chjj I think it's time to close this and just tell people to manually encode the URLs using %29 instead of ).

    —
    Reply to this email directly or view it on GitHub.

  11. sn3p commented on Feb 29, 2016

    @sn3p

    Encoding URLs is not an option :(
    This is a show stopper for us, and I have the feeling this won't be fixed any time soon...
    Guess it's time to switch library. What would be a good alternative?

  12. dedalozzo commented on Feb 29, 2016

    @dedalozzo

    I'm using Hoedown, a PHP extension to the Hoedown library.

  13. joshbruce commented on Dec 25, 2017

    @joshbruce
    Member
  14. added
    L1 - brokenValid usage causes incorrect output OR a crash AND there is no known workaround for the issue
    on Jan 5, 2018
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

    L1 - brokenValid usage causes incorrect output OR a crash AND there is no known workaround for the issuecategory: links

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions