Fix code review feedback from internal UpContent code review

This commit is contained in:
Matthew Beatty 2025-04-28 11:48:58 -04:00
parent 9b678fda97
commit d1a3938b09

View file

@ -340,15 +340,12 @@ func NewRequest(r *http.Request, baseURL *url.URL) (*Request, error) {
var additionalQuery string
req := &Request{Original: r}
path := r.URL.EscapedPath()[1:] // the image url is stored in the path, so get image url from path but strip leading slash so it's not like /https://example.com
path := r.URL.EscapedPath()[1:] // strip leading slash
decodedPath, err, additionalQuery := decodeURL(path) // Conditionally decode url path param if it is url encoded this enables us to process image urls with query params built in
if err == nil {
path = decodedPath
}
req.URL, err = parseURL(path)
if err != nil || !req.URL.IsAbs() {
// first segment should be options
parts := strings.SplitN(path, "/", 2)
@ -405,7 +402,7 @@ func decodeURL(s string) (string, error, string) {
}
var isUrlEncoded = reIsEncodedUrl.MatchString(u)
print(u, ": ", isUrlEncoded, "\n")
if isUrlEncoded {
u, err := url.QueryUnescape(u)
if err != nil {
@ -419,7 +416,7 @@ func decodeURL(s string) (string, error, string) {
return prefix + u, err2, parsed.RawQuery
} else {
return prefix + u, nil, ""
return s, nil, ""
}
}