refactor function joinPaths and isAscii in utils.go #4288
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I would suggest some improvements to further improve robustness and readability
##Proposal
Improve robustness of joinPaths function
Currently, the joinPaths function uses a homebrew lastChar function to determine if a path ends with a trailing slash. lastChar is a potential risk because it panics when passed an empty string. Replacing this logic with strings.HasSuffix, which is safer and clearer in intent, improves robustness and readability.
This change also eliminates the need for the lastChar function,
making the code base simpler.
Simplify isASCII functions
The current isASCII function is implemented using a for loop; it can be rewritten to be more modern and concise using strings.ContainsFunc, available in Go 1.19 and later. is safe.
Delete unnecessary tests
In conjunction with the removal of the lastChar function, we have also removed the associated test in utils_test.go.