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

Method decodePlainURL

options/parser/url.go:55–79  ·  view source on GitHub ↗
(ctx context.Context, parts []string)

Source from the content-addressed store, hash-verified

53}
54
55func (p *Parser) decodePlainURL(ctx context.Context, parts []string) (string, string, error) {
56 var format string
57
58 encoded := strings.Join(parts, "/")
59 urlParts := strings.Split(encoded, "@")
60
61 if len(urlParts[0]) == 0 {
62 return "", "", newInvalidURLError(ctx, "Image URL is empty")
63 }
64
65 if len(urlParts) > 2 {
66 return "", "", newInvalidURLError(ctx, "Multiple formats are specified: %s", encoded)
67 }
68
69 if len(urlParts) == 2 && len(urlParts[1]) > 0 {
70 format = urlParts[1]
71 }
72
73 unescaped, err := url.PathUnescape(urlParts[0])
74 if err != nil {
75 return "", "", newInvalidURLError(ctx, "Invalid url encoding: %s", encoded)
76 }
77
78 return p.preprocessURL(unescaped), format, nil
79}
80
81func (p *Parser) DecodeURL(
82 ctx context.Context,

Callers 1

DecodeURLMethod · 0.95

Calls 3

preprocessURLMethod · 0.95
newInvalidURLErrorFunction · 0.85
SplitMethod · 0.80

Tested by

no test coverage detected