Skip to content

Apply url.QueryUnescape for get image#2130

Merged
cb-github-robot merged 2 commits intocloud-barista:mainfrom
seokho-son:main
Sep 2, 2025
Merged

Apply url.QueryUnescape for get image#2130
cb-github-robot merged 2 commits intocloud-barista:mainfrom
seokho-son:main

Conversation

@seokho-son
Copy link
Copy Markdown
Member

Signed-off-by: seokho-son <shsongist@gmail.com>
Copilot AI review requested due to automatic review settings September 1, 2025 18:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 %2B to + conversion with comprehensive URL decoding using url.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.

Comment on lines +300 to +327
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
}
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I will trust url.QueryUnescape without fallback. :)

@@ -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:\
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the documentation: 'vaious' should be 'various'.

Suggested change
\ for temporal support) This param accepts vaious input types as Image Key:\
\ for temporal support) This param accepts various input types as Image Key:\

Copilot uses AI. Check for mistakes.
{
"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",
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the documentation: 'vaious' should be 'various'.

Suggested change
"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",

Copilot uses AI. Check for mistakes.
{
"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",
Copy link

Copilot AI Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the documentation: 'vaious' should be 'various'.

Suggested change
"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",

Copilot uses AI. Check for mistakes.
@seokho-son
Copy link
Copy Markdown
Member Author

Signed-off-by: Seokho Son <shsongist@gmail.com>
@seokho-son
Copy link
Copy Markdown
Member Author

/approve

@github-actions github-actions bot added the approved This PR is approved and will be merged soon. label Sep 2, 2025
@cb-github-robot cb-github-robot merged commit aaeaa4e into cloud-barista:main Sep 2, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved This PR is approved and will be merged soon.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants