New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gitea panics on a markdown syntax error (nested links) #4946
Comments
I don't get why "visitLinksForShortLinks" logic in modules/markup/html.go is used, where it's used at all. Why nested links should be processed, any working example where they are needed. I cannot remember any example where |
Agreed, I looked through the code myself while trying to debug and couldn’t understand it either. None of tests seem to go through that code path, unless I’m missing something.
… On Sep 19, 2018, at 4:54 PM, SagePtr ***@***.***> wrote:
I don't get why "visitLinksForShortLinks" logic in modules/markup/html.go is used, where it's used at all. Why nested links should be processed, any working example where they are needed.
Probably over-engeneering?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions. |
This bug still causes an uncaught internal server error in production, as you can see from the reproduction I linked in the original post. This issue should not be closed. |
I was looking at all of the link generating code recently and can see whats causing this here. This happens because of a few things: First, the markdown processor does correctly render this and outputs
However, then gitea runs its own processors and this happens to match the following regex: https://github.com/go-gitea/gitea/blob/master/modules/markup/html.go#L53 It does that because it sees anything inside double brackets as a possible MediaWiki/Github style short link like
Relevant comments/function here: https://github.com/go-gitea/gitea/blob/master/modules/markup/html.go#L389 That function seems to assume too much about the text match, and fails when it isn't actually what was expected. This also does other bad things like turn this bogus text into a link:
See: https://try.gitea.io/mrsdizzie/test/issues/2 A quick test of changing shortLinkPattern to
Makes the offending example (and my test) in this issue work as expected, but is complicated because this code is also used for the (imo) separate case of matching basic [[Test]] style wiki links as well. Setting visitLinksForShortLinks: false doesn't seem to affect any of the current tests, and is perhaps an option for fixing this particular issue as well. As mentioned above, I can't imagine the case where it makes sense to try and process an existing link and render another link inside of it (and apparently nobody who wrote the current tests imagined that either). |
The visitLinksForShortLinks feature would look inside of an <a> tag and run shortLinkProcessorFull on any text, which attempts to create links out of potential 'short links' like [[test]] [[link|example]] etc... This makes no sense because you can't have nested links within an <a> tag. Specifically, the html5 standard says <a> tags can't include interactive content if they contain the href attribute: http://w3c.github.io/html/single-page.html#the-a-element And also defines an <a> element with a href attribute as interactive: http://w3c.github.io/html/single-page.html#interactive-content Therefore you can't really put a link inside of another link. In practice none of this works anyways since browsers won't render it, it would probably be broken if they tried, and it is causing a bug (go-gitea#4946). No current tests rely on this behavior either. This removes the feature and also explicitly excludes the current visitNodeForShortLinks from looking in <a> tags.
Closed per merged PR. |
The visitLinksForShortLinks feature would look inside of an <a> tag and run shortLinkProcessorFull on any text, which attempts to create links out of potential 'short links' like [[test]] [[link|example]] etc... This makes no sense because you can't have nested links within an <a> tag. Specifically, the html5 standard says <a> tags can't include interactive content if they contain the href attribute: http://w3c.github.io/html/single-page.html#the-a-element And also defines an <a> element with a href attribute as interactive: http://w3c.github.io/html/single-page.html#interactive-content Therefore you can't really put a link inside of another link. In practice none of this works anyways since browsers won't render it, it would probably be broken if they tried, and it is causing a bug (#4946). No current tests rely on this behavior either. This removes the feature and also explicitly excludes the current visitNodeForShortLinks from looking in <a> tags.
[x]
):Description
The syntax is this:
[\[\[foobar\]\]](https://example.org)
Expected result: [[foobar]]
I noticed it when trying to mirror one of my repos.
The text was updated successfully, but these errors were encountered: