diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2025-01-06 22:45:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-06 22:45:20 +0800 |
commit | 80e4f4c4eb80dbbcd4c306ac05bfcf75a005d742 (patch) | |
tree | 02f976f18ccdd73de0874393838ff6aaa15b2fed /modules | |
parent | ef736b7e27f6eee292183c0f054f1595179db559 (diff) | |
download | gitea-80e4f4c4eb80dbbcd4c306ac05bfcf75a005d742.tar.gz gitea-80e4f4c4eb80dbbcd4c306ac05bfcf75a005d742.zip |
Refactor package (routes and error handling, npm peer dependency) (#33111)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/packages/npm/creator.go | 2 | ||||
-rw-r--r-- | modules/packages/npm/metadata.go | 1 | ||||
-rw-r--r-- | modules/web/router_path.go | 14 |
3 files changed, 16 insertions, 1 deletions
diff --git a/modules/packages/npm/creator.go b/modules/packages/npm/creator.go index 7d3d7cd6b5..8ba4dbfba7 100644 --- a/modules/packages/npm/creator.go +++ b/modules/packages/npm/creator.go @@ -81,6 +81,7 @@ type PackageMetadataVersion struct { BundleDependencies []string `json:"bundleDependencies,omitempty"` DevDependencies map[string]string `json:"devDependencies,omitempty"` PeerDependencies map[string]string `json:"peerDependencies,omitempty"` + PeerDependenciesMeta map[string]any `json:"peerDependenciesMeta,omitempty"` Bin map[string]string `json:"bin,omitempty"` OptionalDependencies map[string]string `json:"optionalDependencies,omitempty"` Readme string `json:"readme,omitempty"` @@ -222,6 +223,7 @@ func ParsePackage(r io.Reader) (*Package, error) { BundleDependencies: meta.BundleDependencies, DevelopmentDependencies: meta.DevDependencies, PeerDependencies: meta.PeerDependencies, + PeerDependenciesMeta: meta.PeerDependenciesMeta, OptionalDependencies: meta.OptionalDependencies, Bin: meta.Bin, Readme: meta.Readme, diff --git a/modules/packages/npm/metadata.go b/modules/packages/npm/metadata.go index 6bb77f302b..d1d0263387 100644 --- a/modules/packages/npm/metadata.go +++ b/modules/packages/npm/metadata.go @@ -19,6 +19,7 @@ type Metadata struct { BundleDependencies []string `json:"bundleDependencies,omitempty"` DevelopmentDependencies map[string]string `json:"development_dependencies,omitempty"` PeerDependencies map[string]string `json:"peer_dependencies,omitempty"` + PeerDependenciesMeta map[string]any `json:"peer_dependencies_meta,omitempty"` OptionalDependencies map[string]string `json:"optional_dependencies,omitempty"` Bin map[string]string `json:"bin,omitempty"` Readme string `json:"readme,omitempty"` diff --git a/modules/web/router_path.go b/modules/web/router_path.go index 39082c0724..b59948581a 100644 --- a/modules/web/router_path.go +++ b/modules/web/router_path.go @@ -89,11 +89,23 @@ func (p *routerPathMatcher) matchPath(chiCtx *chi.Context, path string) bool { return true } +func isValidMethod(name string) bool { + switch name { + case http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodHead, http.MethodOptions, http.MethodConnect, http.MethodTrace: + return true + } + return false +} + func newRouterPathMatcher(methods, pattern string, h ...any) *routerPathMatcher { middlewares, handlerFunc := wrapMiddlewareAndHandler(nil, h) p := &routerPathMatcher{methods: make(container.Set[string]), middlewares: middlewares, handlerFunc: handlerFunc} for _, method := range strings.Split(methods, ",") { - p.methods.Add(strings.TrimSpace(method)) + method = strings.TrimSpace(method) + if !isValidMethod(method) { + panic(fmt.Sprintf("invalid HTTP method: %s", method)) + } + p.methods.Add(method) } re := []byte{'^'} lastEnd := 0 |