Skip to content

fix(deploy/functions): improve list param parsing robustness #8895

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

CorieW
Copy link
Member

@CorieW CorieW commented Jul 24, 2025

expands upon #8891 (forgot to commit these before merged), also added some tests

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @CorieW, 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 focuses on making the parsing of list parameters more resilient and reliable within the Firebase functions deployment process. It refines the core logic for interpreting list-like strings and introduces a comprehensive suite of tests to ensure its correctness and robustness across diverse input formats and edge cases.

Highlights

  • Improved List Parsing Robustness: The ParamValue.asList() method has been significantly enhanced to robustly handle various string representations of lists. It now intelligently attempts to parse the input as a JSON array first. If the input is not a valid JSON array or is malformed (e.g., [a, b, c] instead of ["a", "b", "c"]), it gracefully falls back to splitting the string by the defined delimiter (defaulting to comma).
  • Comprehensive Test Coverage: Extensive new unit tests have been added for the ParamValue.asList() method. These tests cover a wide array of scenarios, including basic usage (JSON arrays, comma-separated values, single values, empty arrays), custom delimiter handling, and numerous robustness cases (e.g., values with internal commas, special characters, empty/whitespace-only strings, various JSON data types like numbers, booleans, nulls, nested arrays, and objects, as well as edge cases with leading/trailing/consecutive delimiters).
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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 or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to improve the robustness of list parameter parsing. The changes introduce logic to handle JSON-formatted arrays in addition to comma-separated strings.

My review focuses on a critical type-safety issue in the new asList implementation, which violates its string[] return type by potentially returning any[]. This could cause runtime errors. I've suggested a fix to enforce the type contract and also to improve the handling of malformed JSON.

Consequently, I've also provided feedback on the new tests to align them with the corrected behavior of asList, ensuring they expect string arrays as per the function's signature.

@taeold
Copy link
Contributor

taeold commented Aug 6, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly improves the robustness of parsing list-type function parameters. The asList() method in ParamValue is updated to handle JSON-formatted arrays more reliably, including various data types and edge cases. It also introduces a fallback to delimiter-based splitting for malformed JSON strings. A comprehensive suite of unit tests has been added to cover these new parsing capabilities and ensure correctness. My review focuses on a small simplification in the implementation. Overall, this is a great improvement.

Comment on lines +303 to +312
if (elem === null) {
// String(null) is "null", which is what we want.
return "null";
}
if (typeof elem === "object") {
// String(obj) is "[object Object]", JSON.stringify is more useful.
// Avoid inserting spaces after commas for objects/arrays
return JSON.stringify(elem);
}
return String(elem);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block of code can be simplified. The if (elem === null) check is redundant because typeof null is 'object', so the subsequent if (typeof elem === 'object') block will handle null values correctly. JSON.stringify(null) produces the string 'null', which is the desired behavior as confirmed by the new test cases.

            if (typeof elem === "object") {
              // This correctly handles objects, arrays, and null.
              // For objects/arrays, JSON.stringify is more useful than the default String() conversion.
              // For null, JSON.stringify(null) results in "null", which is what we want.
              return JSON.stringify(elem);
            }
            return String(elem);

Copy link
Contributor

@taeold taeold left a comment

Choose a reason for hiding this comment

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

lgtm see nits from Gemini

// Handle something like "["a", "b", "c"]"
if (modifiedValue.startsWith("[") && modifiedValue.endsWith("]")) {
try {
const parsed = JSON.parse(modifiedValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

ha this is clever way to parse arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants