-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Only turn links to current instance into hash links #36237
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
Draft
silverwind
wants to merge
6
commits into
go-gitea:main
Choose a base branch
from
silverwind:hashlinks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+28
−15
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26904e8
Only turn links to current instance into hash links
silverwind 1793e51
simplify
silverwind 7e0a1e4
fix TestRenderLinks
silverwind c85aee1
fix tests
silverwind 79c63e0
remove slash
silverwind b33a247
fix TestRender_AutoLink
silverwind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -484,20 +484,20 @@ foo: bar | |
| func TestRenderLinks(t *testing.T) { | ||
| input := ` space @mention-user${SPACE}${SPACE} | ||
| /just/a/path.bin | ||
| https://example.com/file.bin | ||
| http://localhost:3000/file.bin | ||
| [local link](file.bin) | ||
| [remote link](https://example.com) | ||
| [remote link](http://localhost:3000) | ||
| [[local link|file.bin]] | ||
| [[remote link|https://example.com]] | ||
| [[remote link|http://localhost:3000]] | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
| [[local image|image.jpg]] | ||
| [[remote link|https://example.com/image.jpg]] | ||
| https://example.com/user/repo/compare/88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb#hash | ||
| [[remote link|http://localhost:3000/image.jpg]] | ||
| http://localhost:3000/user/repo/compare/88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb#hash | ||
| com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb pare | ||
| https://example.com/user/repo/commit/88fc37a3c0a4dda553bdcfc80c178a58247f42fb | ||
| http://localhost:3000/user/repo/commit/88fc37a3c0a4dda553bdcfc80c178a58247f42fb | ||
| com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit | ||
| :+1: | ||
| [email protected] | ||
|
|
@@ -508,20 +508,20 @@ [email protected] | |
| input = strings.ReplaceAll(input, "${SPACE}", " ") // replace ${SPACE} with " ", to avoid some editor's auto-trimming | ||
| expected := `<p>space @mention-user<br/> | ||
| /just/a/path.bin | ||
| <a href="https://example.com/file.bin" rel="nofollow">https://example.com/file.bin</a> | ||
| <a href="http://localhost:3000/file.bin" rel="nofollow">http://localhost:3000/file.bin</a> | ||
| <a href="/file.bin" rel="nofollow">local link</a> | ||
| <a href="https://example.com" rel="nofollow">remote link</a> | ||
| <a href="http://localhost:3000" rel="nofollow">remote link</a> | ||
| <a href="/file.bin" rel="nofollow">local link</a> | ||
| <a href="https://example.com" rel="nofollow">remote link</a> | ||
| <a href="http://localhost:3000" rel="nofollow">remote link</a> | ||
| <a href="/image.jpg" target="_blank" rel="nofollow noopener"><img src="/image.jpg" alt="local image"/></a> | ||
| <a href="/path/file" target="_blank" rel="nofollow noopener"><img src="/path/file" alt="local image"/></a> | ||
| <a href="/path/file" target="_blank" rel="nofollow noopener"><img src="/path/file" alt="local image"/></a> | ||
| <a href="https://example.com/image.jpg" target="_blank" rel="nofollow noopener"><img src="https://example.com/image.jpg" alt="remote image"/></a> | ||
| <a href="http://localhost:3000/image.jpg" target="_blank" rel="nofollow noopener"><img src="http://localhost:3000/image.jpg" alt="remote image"/></a> | ||
| <a href="/image.jpg" rel="nofollow"><img src="/image.jpg" title="local image" alt="local image"/></a> | ||
| <a href="https://example.com/image.jpg" rel="nofollow"><img src="https://example.com/image.jpg" title="remote link" alt="remote link"/></a> | ||
| <a href="https://example.com/user/repo/compare/88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb#hash" rel="nofollow"><code>88fc37a3c0...12fc37a3c0 (hash)</code></a> | ||
| <a href="http://localhost:3000/image.jpg" rel="nofollow"><img src="http://localhost:3000/image.jpg" title="remote link" alt="remote link"/></a> | ||
| <a href="http://localhost:3000/user/repo/compare/88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb#hash" rel="nofollow"><code>88fc37a3c0...12fc37a3c0 (hash)</code></a> | ||
| com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb...12fc37a3c0a4dda553bdcfc80c178a58247f42fb pare | ||
| <a href="https://example.com/user/repo/commit/88fc37a3c0a4dda553bdcfc80c178a58247f42fb" rel="nofollow"><code>88fc37a3c0</code></a> | ||
| <a href="http://localhost:3000/user/repo/commit/88fc37a3c0a4dda553bdcfc80c178a58247f42fb" rel="nofollow"><code>88fc37a3c0</code></a> | ||
| com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit | ||
| <span class="emoji" aria-label="thumbs up">👍</span> | ||
| <a href="mailto:[email protected]" rel="nofollow">[email protected]</a> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multidomain support #8697
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what do we check instead of
setting.AppURL? Is there a slice of "current app urls" somewhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no "current app urls" at the moment.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make
server.ROOT_URLaccept multiple URLs comma-separated, and then check against all of those.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is there a way to obtain the current URL/Origin in this function? Do we need to pass
*http.Requestor some context down all the way to this function?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the only way to make it work based on request URL is to determine the current HTTP request origin (from HTTP headers
Host,X-Forwarded-Host,X-Forwarded-Protocoland more) intomarkup.RenderContext, which will be quite complicated.It'll certainly be easier to let the user configure multiple
server.ROOT_URL.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this can be used:
gitea/modules/httplib/url.go
Line 58 in eddf875