Apply url.QueryUnescape for get image#2130
Apply url.QueryUnescape for get image#2130cb-github-robot merged 2 commits intocloud-barista:mainfrom
Conversation
Signed-off-by: seokho-son <shsongist@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This PR improves URL-encoded parameter handling in the image retrieval endpoint by replacing manual URL decoding with Go's built-in url.QueryUnescape function. The change addresses issue #194 related to properly decoding URL-encoded characters in image IDs.
- Replaces manual
%2Bto+conversion with comprehensive URL decoding usingurl.QueryUnescape - Adds fallback manual decoding for common URL-encoded characters when the built-in function fails
- Updates API documentation to clarify accepted imageId parameter formats
- Includes response body truncation functionality for debug logging
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/interface/rest/server/resource/image.go | Implements proper URL decoding for image keys with fallback handling |
| src/interface/rest/docs/swagger.yaml | Updates API documentation descriptions for image parameter formats |
| src/interface/rest/docs/swagger.json | Updates generated swagger JSON documentation |
| src/interface/rest/docs/docs.go | Updates generated Go documentation template |
| src/core/common/client/client.go | Adds response body truncation for debug logging (unrelated to main PR purpose) |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| log.Warn().Err(err).Msgf("Failed to URL decode imageKey: %s, using original", imageKey) | ||
| // Fall back to manual decoding for common characters | ||
| imageKey = strings.ReplaceAll(imageKey, "%2B", "+") // + | ||
| imageKey = strings.ReplaceAll(imageKey, "%3A", ":") // : | ||
| imageKey = strings.ReplaceAll(imageKey, "%2F", "/") // / | ||
| imageKey = strings.ReplaceAll(imageKey, "%3F", "?") // ? | ||
| imageKey = strings.ReplaceAll(imageKey, "%23", "#") // # | ||
| imageKey = strings.ReplaceAll(imageKey, "%26", "&") // & | ||
| imageKey = strings.ReplaceAll(imageKey, "%3D", "=") // = | ||
| imageKey = strings.ReplaceAll(imageKey, "%25", "%") // % (handle this last to avoid double decoding) | ||
| imageKey = strings.ReplaceAll(imageKey, "%40", "@") // @ | ||
| imageKey = strings.ReplaceAll(imageKey, "%21", "!") // ! | ||
| imageKey = strings.ReplaceAll(imageKey, "%2A", "*") // * | ||
| imageKey = strings.ReplaceAll(imageKey, "%28", "(") // ( | ||
| imageKey = strings.ReplaceAll(imageKey, "%29", ")") // ) | ||
| imageKey = strings.ReplaceAll(imageKey, "%5B", "[") // [ | ||
| imageKey = strings.ReplaceAll(imageKey, "%5D", "]") // ] | ||
| imageKey = strings.ReplaceAll(imageKey, "%7B", "{") // { | ||
| imageKey = strings.ReplaceAll(imageKey, "%7D", "}") // } | ||
| imageKey = strings.ReplaceAll(imageKey, "%7C", "|") // | | ||
| imageKey = strings.ReplaceAll(imageKey, "%5C", "\\") // \ | ||
| imageKey = strings.ReplaceAll(imageKey, "%5E", "^") // ^ | ||
| imageKey = strings.ReplaceAll(imageKey, "%7E", "~") // ~ | ||
| imageKey = strings.ReplaceAll(imageKey, "%60", "`") // ` | ||
| imageKey = strings.ReplaceAll(imageKey, "%20", " ") // space | ||
| } else { | ||
| imageKey = decodedImageKey | ||
| } |
There was a problem hiding this comment.
This extensive fallback manual decoding logic is complex and duplicates functionality already available in the standard library. Consider investigating why url.QueryUnescape would fail for valid URL-encoded strings, as this should handle all these cases. If specific edge cases exist that require fallback, document them clearly and simplify the fallback to only handle those specific cases.
| log.Warn().Err(err).Msgf("Failed to URL decode imageKey: %s, using original", imageKey) | |
| // Fall back to manual decoding for common characters | |
| imageKey = strings.ReplaceAll(imageKey, "%2B", "+") // + | |
| imageKey = strings.ReplaceAll(imageKey, "%3A", ":") // : | |
| imageKey = strings.ReplaceAll(imageKey, "%2F", "/") // / | |
| imageKey = strings.ReplaceAll(imageKey, "%3F", "?") // ? | |
| imageKey = strings.ReplaceAll(imageKey, "%23", "#") // # | |
| imageKey = strings.ReplaceAll(imageKey, "%26", "&") // & | |
| imageKey = strings.ReplaceAll(imageKey, "%3D", "=") // = | |
| imageKey = strings.ReplaceAll(imageKey, "%25", "%") // % (handle this last to avoid double decoding) | |
| imageKey = strings.ReplaceAll(imageKey, "%40", "@") // @ | |
| imageKey = strings.ReplaceAll(imageKey, "%21", "!") // ! | |
| imageKey = strings.ReplaceAll(imageKey, "%2A", "*") // * | |
| imageKey = strings.ReplaceAll(imageKey, "%28", "(") // ( | |
| imageKey = strings.ReplaceAll(imageKey, "%29", ")") // ) | |
| imageKey = strings.ReplaceAll(imageKey, "%5B", "[") // [ | |
| imageKey = strings.ReplaceAll(imageKey, "%5D", "]") // ] | |
| imageKey = strings.ReplaceAll(imageKey, "%7B", "{") // { | |
| imageKey = strings.ReplaceAll(imageKey, "%7D", "}") // } | |
| imageKey = strings.ReplaceAll(imageKey, "%7C", "|") // | | |
| imageKey = strings.ReplaceAll(imageKey, "%5C", "\\") // \ | |
| imageKey = strings.ReplaceAll(imageKey, "%5E", "^") // ^ | |
| imageKey = strings.ReplaceAll(imageKey, "%7E", "~") // ~ | |
| imageKey = strings.ReplaceAll(imageKey, "%60", "`") // ` | |
| imageKey = strings.ReplaceAll(imageKey, "%20", " ") // space | |
| } else { | |
| imageKey = decodedImageKey | |
| } | |
| log.Error().Err(err).Msgf("Failed to URL decode imageKey: %s", imageKey) | |
| return echo.NewHTTPError(400, fmt.Sprintf("Invalid imageKey encoding: %s", imageKey)) | |
| } | |
| imageKey = decodedImageKey |
There was a problem hiding this comment.
ok. I will trust url.QueryUnescape without fallback. :)
src/interface/rest/docs/swagger.yaml
Outdated
| @@ -6567,7 +6567,7 @@ paths: | |||
| in: path | |||
| description: "(Note: imageId param will be refined in next release, enabled\ | |||
| \ for temporal support) This param accepts vaious input types as Image Key:\ | |||
There was a problem hiding this comment.
There's a typo in the documentation: 'vaious' should be 'various'.
| \ for temporal support) This param accepts vaious input types as Image Key:\ | |
| \ for temporal support) This param accepts various input types as Image Key:\ |
src/interface/rest/docs/swagger.json
Outdated
| { | ||
| "type": "string", | ||
| "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts vaious input types as Image Key: cspImageName", | ||
| "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts vaious input types as Image Key: 1) provider+imageId, 2) provider+region+imageId, 3) imageId", |
There was a problem hiding this comment.
There's a typo in the documentation: 'vaious' should be 'various'.
| "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts vaious input types as Image Key: 1) provider+imageId, 2) provider+region+imageId, 3) imageId", | |
| "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts various input types as Image Key: 1) provider+imageId, 2) provider+region+imageId, 3) imageId", |
src/interface/rest/docs/docs.go
Outdated
| { | ||
| "type": "string", | ||
| "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts vaious input types as Image Key: cspImageName", | ||
| "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts vaious input types as Image Key: 1) provider+imageId, 2) provider+region+imageId, 3) imageId", |
There was a problem hiding this comment.
There's a typo in the documentation: 'vaious' should be 'various'.
| "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts vaious input types as Image Key: 1) provider+imageId, 2) provider+region+imageId, 3) imageId", | |
| "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts various input types as Image Key: 1) provider+imageId, 2) provider+region+imageId, 3) imageId", |
|
Alibaba
Azure
AWS |
Signed-off-by: Seokho Son <shsongist@gmail.com>
|
/approve |
But, I will double check :)