-
-
Notifications
You must be signed in to change notification settings - Fork 577
fix(web): include base prefix in generated URLs #1403
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,7 +64,7 @@ | |
| @templ.JSONScript("anubis_public_url", anubis.PublicUrl) | ||
| </head> | ||
| <body id="top"> | ||
| @honeypotLink(fmt.Sprintf("%shoneypot/%s/init", anubis.APIPrefix, uuid.NewString())) | ||
| @honeypotLink(anubis.BasePrefix + fmt.Sprintf("%shoneypot/%s/init", anubis.APIPrefix, uuid.NewString())) | ||
Check warningCode scanning / check-spelling Candidate Pattern Warning
Line matches candidate pattern (This does not cover multiline strings, if your repository has them,) %(?:(?:(?:hh?|ll?|[jzt])?[diuoxn]|l?[cs]|L?[fega]|p)(?=[a-z]{2,})|(?:X|L?[FEGA])(?=[a-zA-Z]{2,}))(…
|
||
| <main> | ||
| <h1 id="title" class="centered-div">{ title }</h1> | ||
| @body | ||
|
|
@@ -79,7 +79,7 @@ | |
| if impressum != nil { | ||
| <p> | ||
| @templ.Raw(impressum.Footer) | ||
| -- <a href={ templ.SafeURL(fmt.Sprintf("%simprint", anubis.APIPrefix)) }>Imprint</a> | ||
| -- <a href={ templ.SafeURL(anubis.BasePrefix + fmt.Sprintf("%simprint", anubis.APIPrefix)) }>Imprint</a> | ||
| </p> | ||
| } | ||
| <p>{ localizer.T("version_info") } <code>{ anubis.Version }</code>.</p> | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package web | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/TecharoHQ/anubis" | ||
| "github.com/TecharoHQ/anubis/lib/config" | ||
| "github.com/TecharoHQ/anubis/lib/localization" | ||
| "github.com/a-h/templ" | ||
| ) | ||
|
|
||
| func TestBasePrefixInLinks(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| basePrefix string | ||
| wantInLink string | ||
| }{ | ||
| { | ||
| name: "no prefix", | ||
| basePrefix: "", | ||
| wantInLink: "/.within.website/x/cmd/anubis/api/", | ||
| }, | ||
| { | ||
| name: "with rififi prefix", | ||
|
|
||
| basePrefix: "/rififi", | ||
|
|
||
| wantInLink: "/rififi/.within.website/x/cmd/anubis/api/", | ||
|
|
||
| }, | ||
| { | ||
| name: "with myapp prefix", | ||
| basePrefix: "/myapp", | ||
| wantInLink: "/myapp/.within.website/x/cmd/anubis/api/", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| // Save original BasePrefix and restore after test | ||
| origPrefix := anubis.BasePrefix | ||
| defer func() { anubis.BasePrefix = origPrefix }() | ||
|
|
||
| anubis.BasePrefix = tt.basePrefix | ||
|
|
||
| // Create test impressum | ||
| impressum := &config.Impressum{ | ||
| Footer: "<p>Test footer</p>", | ||
| Page: config.ImpressumPage{ | ||
| Title: "Test Imprint", | ||
| Body: "<p>Test imprint body</p>", | ||
| }, | ||
| } | ||
|
|
||
| // Create localizer using a dummy request | ||
| req := httptest.NewRequest("GET", "/", nil) | ||
| localizer := &localization.SimpleLocalizer{} | ||
| localizer.Localizer = localization.NewLocalizationService().GetLocalizerFromRequest(req) | ||
|
|
||
| // Render the base template to a buffer | ||
| var buf strings.Builder | ||
| component := base(tt.name, templ.NopComponent, impressum, nil, nil, localizer) | ||
| err := component.Render(context.Background(), &buf) | ||
| if err != nil { | ||
| t.Fatalf("failed to render template: %v", err) | ||
| } | ||
|
|
||
| output := buf.String() | ||
|
|
||
| // Check that honeypot link includes the base prefix | ||
| if !strings.Contains(output, `href="`+tt.wantInLink+`honeypot/`) { | ||
| t.Errorf("honeypot link does not contain base prefix %q\noutput: %s", tt.wantInLink, output) | ||
| } | ||
|
|
||
| // Check that imprint link includes the base prefix | ||
| if !strings.Contains(output, `href="`+tt.wantInLink+`imprint`) { | ||
| t.Errorf("imprint link does not contain base prefix %q\noutput: %s", tt.wantInLink, output) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Check warning
Code scanning / check-spelling
Candidate Pattern Warning