Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(request_builder): encode unresolved path string prior to path parameter insertion #219

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test:

lint:
${LINT} run --build-tags=all
DIFF=$$(${FORMATTER} -d core); if [[ -n "$$DIFF" ]]; then printf "\n$$DIFF" && exit 1; fi
DIFF=$$(${FORMATTER} -d core); if [ -n "$$DIFF" ]; then printf "\n$$DIFF\n" && exit 1; fi
Copy link
Member Author

Choose a reason for hiding this comment

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

It turns out that this statement was always failing on Travis but yet it did not cause the build to stop due to a difference between "bash" and "sh" (the default shell on a Travis build agent is "sh").

Example build hiccup:
https://app.travis-ci.com/github/IBM/go-sdk-core/jobs/621470281

$ make lint
golangci-lint run --build-tags=all
DIFF=$(goimports -d core); if [[ -n "$DIFF" ]]; then printf "\n$DIFF" && exit 1; fi
/bin/sh: 1: [[: not found
The command "make lint" exited with 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

I verified that any formatting type differences will now cause the build to fail and "make" will return a non-zero exit status.

Copy link
Member

Choose a reason for hiding this comment

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

Wow, good catch! I think I was the one who wrote that line and... I never thought about the shell difference to be honest - since we use Ubuntu images that usually use bash by default.


scan-gosec:
${GOSEC} ./...
Expand Down
8 changes: 8 additions & 0 deletions core/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ func (requestBuilder *RequestBuilder) ResolveRequestURL(serviceURL string, path
// If we have a non-empty "path" input parameter, then process it for possible path param references.
if path != "" {

// Encode the unresolved path string. This will convert all special characters to their
// "%" encoding counterparts. Then we need to revert the encodings for '/', '{' and '}' characters
// to retain the original path segments and to make it easy to insert the encoded path param values below.
path = url.PathEscape(path)
path = strings.ReplaceAll(path, "%2F", "/")
path = strings.ReplaceAll(path, "%7B", "{")
path = strings.ReplaceAll(path, "%7D", "}")

// If path parameter values were passed in, then for each one, replace any references to it
// within "path" with the path parameter's encoded value.
if len(pathParams) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion core/sdk_problem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TestSDKErrorfNoSummary(t *testing.T) {
}

func TestSDKErrorfDoesntUseSDKCausedBy(t *testing.T) {
sdkProb := getPopulatedSDKProblem();
sdkProb := getPopulatedSDKProblem()
Copy link
Member Author

Choose a reason for hiding this comment

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

change by "make format"

newSDKProb := SDKErrorf(sdkProb, "", "", NewProblemComponent("a", "b"))
assert.Nil(t, newSDKProb.causedBy)
assert.NotNil(t, newSDKProb.nativeCausedBy)
Expand Down
4 changes: 2 additions & 2 deletions core/sdk_problem_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ func formatFrames(pcs []uintptr, componentName string) []sdkStackFrame {
}

type sparseSDKProblem struct {
ID string
ID string
Copy link
Member Author

Choose a reason for hiding this comment

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

changes by "make format"

Function string
}

func newSparseSDKProblem(prob *SDKProblem) *sparseSDKProblem {
return &sparseSDKProblem{
ID: prob.GetID(),
ID: prob.GetID(),
Function: prob.Function,
}
}
Expand Down