MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / parseURLPath

Function parseURLPath

env/parsers.go:101–119  ·  view source on GitHub ↗

parseURLPath normalizes a URL path by removing query strings and fragments, ensuring it has a leading slash and no trailing slash.

(env string)

Source from the content-addressed store, hash-verified

99// parseURLPath normalizes a URL path by removing query strings and fragments,
100// ensuring it has a leading slash and no trailing slash.
101func parseURLPath(env string) (string, error) {
102 // Remove query string
103 if i := strings.IndexByte(env, '?'); i >= 0 {
104 env = env[:i]
105 }
106 // Remove fragment
107 if i := strings.IndexByte(env, '#'); i >= 0 {
108 env = env[:i]
109 }
110 // Remove trailing slash
111 if len(env) > 0 && env[len(env)-1] == '/' {
112 env = env[:len(env)-1]
113 }
114 // Ensure leading slash
115 if len(env) > 0 && env[0] != '/' {
116 env = "/" + env
117 }
118 return env, nil
119}
120
121// parseImageTypes parses a comma-separated list of image format names and returns
122// a slice of imagetype.Type values.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected