fix: assign decodedData when input is string#629
Conversation
Fixes uninitialized variable bug where decodedData was undefined when the input parameter was already a string, causing subsequent calls to isBase64Encoded and btoa to fail.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: deb7ec5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a bug in the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request correctly fixes a bug where decodedData was uninitialized if the input was a string. I've added one suggestion to make the code more concise by using a ternary operator for initialization, which also allows for using const.
| let decodedData: string; | ||
| if (data instanceof ArrayBuffer) { | ||
| decodedData = new TextDecoder().decode(data); | ||
| } else { | ||
| decodedData = data; | ||
| } |
There was a problem hiding this comment.
While the fix is correct, this logic can be made more concise by using a ternary operator for initialization. This also allows decodedData to be declared with const, which is a good practice for variables that are not reassigned.
| let decodedData: string; | |
| if (data instanceof ArrayBuffer) { | |
| decodedData = new TextDecoder().decode(data); | |
| } else { | |
| decodedData = data; | |
| } | |
| const decodedData = data instanceof ArrayBuffer ? new TextDecoder().decode(data) : data; |
Address PR feedback: simplify if/else to const ternary assignment. Add changeset for patch version bump.
Description
When reading file content, the code had a bug where it only handled one type of input (binary data) but forgot to handle the other (plain text). This meant passing text to the function would silently break because the variable holding the result was never set. The fix simply assigns the text input so both paths work correctly.
Type of Change
How Has This Been Tested?
All existing tests pass (478 tests in the adk package). The fix ensures both input types (binary and text) are properly handled before use.
Checklist