-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fixed an error that occurred when an author name contains a string that is not suitable for JSON #3638
Fixed an error that occurred when an author name contains a string that is not suitable for JSON #3638
Conversation
…author name contained non-JSON legal characters.
WalkthroughThe recent updates to the Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- v2/pkg/git/git.go (2 hunks)
Additional comments not posted (1)
v2/pkg/git/git.go (1)
39-41
: Ensure proper escaping of the username.The
template.JSEscapeString
function is used to escape the username. This is a good practice to prevent injection attacks.
v2/pkg/git/git.go
Outdated
if err != nil { | ||
return "", err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enhance error handling message.
The error handling can be improved by providing a more descriptive error message.
- return "", err
+ return "", fmt.Errorf("failed to retrieve git user name: %w", err)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if err != nil { | |
return "", err | |
} | |
if err != nil { | |
return "", fmt.Errorf("failed to retrieve git user name: %w", err) | |
} |
v2/pkg/git/git.go
Outdated
// Check if username is JSON compliant | ||
var js json.RawMessage | ||
jsonVal := fmt.Sprintf(`{"name": "%s"}`, name) | ||
err = json.Unmarshal([]byte(jsonVal), &js) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve JSON validation and error handling.
The JSON validation is a good addition to ensure the username is JSON compliant. However, the error handling can be improved by providing a more descriptive error message.
- return name, err
+ if err != nil {
+ return "", fmt.Errorf("username is not JSON compliant: %w", err)
+ }
+ return name, nil
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// Check if username is JSON compliant | |
var js json.RawMessage | |
jsonVal := fmt.Sprintf(`{"name": "%s"}`, name) | |
err = json.Unmarshal([]byte(jsonVal), &js) | |
// Check if username is JSON compliant | |
var js json.RawMessage | |
jsonVal := fmt.Sprintf(`{"name": "%s"}`, name) | |
err = json.Unmarshal([]byte(jsonVal), &js) | |
if err != nil { | |
return "", fmt.Errorf("username is not JSON compliant: %w", err) | |
} | |
return name, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- v2/pkg/git/git.go (2 hunks)
- website/src/pages/changelog.mdx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- v2/pkg/git/git.go
Additional comments not posted (2)
website/src/pages/changelog.mdx (2)
18-18
: LGTM!The entry clearly describes the bug fix related to author names containing unsuitable strings for JSON formatting.
19-19
: LGTM!The consolidation of the entries regarding file drop events on Windows is clear and follows the changelog format.
Tools
LanguageTool
[grammar] ~19-~19: The operating system from Apple is written “macOS”.
Context: ...b.com//pull/3638) - Fixed MacOS build to useoutputfilename
from wail...(MAC_OS)
[imo] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- v2/pkg/git/git.go (2 hunks)
- v2/pkg/git/git_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- v2/pkg/git/git.go
Additional comments not posted (4)
v2/pkg/git/git_test.go (4)
1-7
: LGTM!The package declaration and imports are appropriate and necessary for the test function.
9-18
: LGTM!The test function
TestEscapeName1
is declared correctly and uses a table-driven approach for the test cases, which is a good practice.
19-33
: Verify the expected output for the apostrophe case.The test case for escaping an apostrophe expects the output to be
John O'Keefe
. Ensure this is the correct expected output based on theEscapeName
function's implementation.
34-49
: LGTM!The test execution loop correctly runs each test case and validates both the function output and the JSON parsing, ensuring comprehensive testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one @taisei-86!
I added a couple of changes and a test. Glad to finally put this one to bed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- v2/pkg/git/git_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- v2/pkg/git/git_test.go
Quality Gate passedIssues Measures |
…at is not suitable for JSON (wailsapp#3638) * fix(pkg): Fixed an issue where wails new would throw an error if the author name contained non-JSON legal characters. * refactor(pkg): Incorporating coderabbit's suggestions * docs: write changelog.mdx * Escape using json package. Add tests. * Update test. --------- Co-authored-by: Lea O'Anthony <lea.anthony@gmail.com>
Description
When running wails dev, an error occurs in json.Unmarshal in project.go.
Reason: If git user.name contains a ', it will be escaped as "\'", making it unsuitable for a json string.
Fixes #3128
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I ran wails init & go build & wails(binary) dev and it was successful.
Test Configuration
Please paste the output of
wails doctor
. If you are unable to run this command, please describe your environment in as much detail as possible.Checklist:
website/src/pages/changelog.mdx
with details of this PRSummary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Documentation