-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
admin/files: support %(theme)s variable in media file paths #19108
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
4 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
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 |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package web | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestPathMatchesWithTheme(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| jwtPath string | ||
| requestedPath string | ||
| want bool | ||
| }{ | ||
| { | ||
| name: "exact match without theme variable", | ||
| jwtPath: "media/public/logo.png", | ||
| requestedPath: "media/public/logo.png", | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "no match without theme variable", | ||
| jwtPath: "media/public/logo.png", | ||
| requestedPath: "media/public/other.png", | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "theme variable matches light theme", | ||
| jwtPath: "media/public/logo-%(theme)s.png", | ||
| requestedPath: "media/public/logo-light.png", | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "theme variable matches dark theme", | ||
| jwtPath: "media/public/logo-%(theme)s.png", | ||
| requestedPath: "media/public/logo-dark.png", | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "theme variable does not match invalid theme", | ||
| jwtPath: "media/public/logo-%(theme)s.png", | ||
| requestedPath: "media/public/logo-blue.png", | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "theme variable in directory path", | ||
| jwtPath: "media/%(theme)s/logo.png", | ||
| requestedPath: "media/light/logo.png", | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "multiple theme variables", | ||
| jwtPath: "media/%(theme)s/logo-%(theme)s.png", | ||
| requestedPath: "media/light/logo-light.png", | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "multiple theme variables with dark", | ||
| jwtPath: "media/%(theme)s/logo-%(theme)s.png", | ||
| requestedPath: "media/dark/logo-dark.png", | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "multiple theme variables mixed themes should not match", | ||
| jwtPath: "media/%(theme)s/logo-%(theme)s.png", | ||
| requestedPath: "media/light/logo-dark.png", | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "theme variable with nested path", | ||
| jwtPath: "media/public/brand/logo-%(theme)s.svg", | ||
| requestedPath: "media/public/brand/logo-dark.svg", | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "empty paths", | ||
| jwtPath: "", | ||
| requestedPath: "", | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "theme variable only", | ||
| jwtPath: "%(theme)s", | ||
| requestedPath: "light", | ||
| want: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := pathMatchesWithTheme(tt.jwtPath, tt.requestedPath) | ||
| if got != tt.want { | ||
| t.Errorf("pathMatchesWithTheme(%q, %q) = %v, want %v", | ||
| tt.jwtPath, tt.requestedPath, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.