Skip to content
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

fix: allow LICENSE rendering via gnoweb #2417

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gno.land/pkg/gnoweb/gnoweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func MakeApp(logger *slog.Logger, cfg Config) gotuna.App {
}
// realm routes
// NOTE: see rePathPart.
app.Router.Handle("/r/{rlmname:[a-z][a-z0-9_]*(?:/[a-z][a-z0-9_]*)+}/{filename:(?:.*\\.(?:gno|md|txt|mod)$)?}", handlerRealmFile(logger, app, &cfg))
app.Router.Handle("/r/{rlmname:[a-z][a-z0-9_]*(?:/[a-z][a-z0-9_]*)+}/{filename:(?:(?:.*\\.(?:gno|md|txt|mod)$)|(?:LICENSE$))?}", handlerRealmFile(logger, app, &cfg))
app.Router.Handle("/r/{rlmname:[a-z][a-z0-9_]*(?:/[a-z][a-z0-9_]*)+}", handlerRealmMain(logger, app, &cfg))
app.Router.Handle("/r/{rlmname:[a-z][a-z0-9_]*(?:/[a-z][a-z0-9_]*)+}:{querystr:.*}", handlerRealmRender(logger, app, &cfg))
app.Router.Handle("/p/{filepath:.*}", handlerPackageFile(logger, app, &cfg))
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 3 additions & 1 deletion gno.land/pkg/gnoweb/gnoweb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func TestRoutes(t *testing.T) {
{"/%ED%85%8C%EC%8A%A4%ED%8A%B8", notFound, "/테스트"},
{"/グノー", notFound, "/グノー"},
{"/⚛️", notFound, "/⚛️"},
{"/p/demo/flow/LICENSE", ok, "BSD 3-Clause"},
}

config, _ := integration.TestingNodeConfig(t, gnoenv.RootDir())
Expand All @@ -68,7 +69,8 @@ func TestRoutes(t *testing.T) {
app.Router.ServeHTTP(response, request)
assert.Equal(t, r.status, response.Code)

assert.Contains(t, response.Body.String(), r.substring)
body := response.Body.String()
assert.Contains(t, body, r.substring)
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
})
}
}
Expand Down
4 changes: 4 additions & 0 deletions tm2/pkg/std/memfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
return nil
}

const licenseName = "LICENSE"
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

// Splits a path into the dirpath and filename.
func SplitFilepath(filepath string) (dirpath string, filename string) {
parts := strings.Split(filepath, "/")
Expand All @@ -101,6 +103,8 @@
return strings.Join(parts[:len(parts)-1], "/"), last
} else if last == "" {
return strings.Join(parts[:len(parts)-1], "/"), ""
} else if last == licenseName {
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
return strings.Join(parts[:len(parts)-1], "/"), licenseName

Check warning on line 107 in tm2/pkg/std/memfile.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/std/memfile.go#L106-L107

Added lines #L106 - L107 were not covered by tests
} else {
return strings.Join(parts, "/"), ""
}
Expand Down
Loading