Skip to content

fix(cli): validate finite numbers in numeric settings editor - #29968

Merged
DavidAPierce merged 3 commits into
google-gemini:mainfrom
diegogodinezr:fix/numeric-settings-finite-validation
Oct 26, 2026
Merged

DavidAPierce merged 3 commits into
google-gemini:mainfrom
diegogodinezr:fix/numeric-settings-finite-validation

Conversation

@diegogodinezr

Copy link
Copy Markdown
Contributor

Summary

Replace Number.isNaN with Number.isFinite in parseEditedValue within
packages/cli/src/utils/settingsUtils.ts so that non-finite values return
null instead of passing to the serializer.

Details

  • The previous Number.isNaN check accepted Infinity and -Infinity,
    including numeric input that exceeds the double-precision range. JSON
    serialization (comment-json / JSON.stringify) writes non-finite numbers
    as null, so these values replaced the stored setting with null.
  • Number.isFinite rejects NaN, Infinity, and -Infinity. All finite
    values accepted before are still accepted.
  • SettingsDialog already treats a null result from parseEditedValue as
    invalid input and keeps the existing value, so no UI changes are needed.
  • Only the number branch changes; string, array, and object parsing are
    untouched. No breaking changes and no documentation updates.

Related Issues

Fixes #29226

Related to #29229 (earlier PR with the same approach)

How to Validate

Added unit test coverage in packages/cli/src/utils/settingsUtils.test.ts
verifying parsing of finite numbers, scientific notation, and rejection of
non-finite numbers and strings.

  1. Run the settings utils tests:

    npx vitest run src/utils/settingsUtils.test.ts --root packages/cli

    Expected: 63 tests pass (49 existing + 14 new).

  2. Run the SettingsDialog tests (the only caller of parseEditedValue):

    npx vitest run src/ui/components/SettingsDialog.test.tsx --root packages/cli

    Expected: 64 tests pass with snapshots unchanged.

  3. Run the full repository checks:

    npm run preflight

Edge cases covered by the new tests: integers, decimals, negative values,
scientific notation, surrounding whitespace, values beyond the double-precision
range, Infinity, -Infinity, NaN, empty and whitespace-only input,
non-numeric strings, and a string-typed setting (unaffected by numeric
validation).

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

Update parseEditedValue to validate numeric values using Number.isFinite,
preventing non-finite values from being serialized as null in settings storage.

Closes google-gemini#29226
@diegogodinezr
diegogodinezr requested a review from a team as a code owner October 26, 2026 19:23
@github-actions github-actions Bot added the size/s A small PR label Oct 26, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 37
  • Additions: +36
  • Deletions: -1
  • Files changed: 2

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 improves the robustness of the numeric settings editor by ensuring that only finite numbers are accepted. By switching from Number.isNaN to Number.isFinite, the application now correctly prevents non-finite values from being processed, maintaining data integrity for numeric settings and avoiding unexpected null values during serialization.

Highlights

  • Improved numeric validation: Replaced Number.isNaN with Number.isFinite in parseEditedValue to correctly reject non-finite numbers like Infinity and NaN, preventing them from being serialized as null.
  • Expanded test coverage: Added comprehensive unit tests in settingsUtils.test.ts to verify parsing of finite numbers, scientific notation, and the rejection of non-finite or invalid numeric inputs.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the 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 counterproductive. 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

  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. ↩

@diegogodinezr

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 updates the parseEditedValue function in packages/cli/src/utils/settingsUtils.ts to reject non-finite numbers (such as NaN and ±Infinity) by replacing the Number.isNaN check with !Number.isFinite. This prevents serialization issues since JSON cannot represent non-finite numbers. Additionally, comprehensive unit tests have been added in packages/cli/src/utils/settingsUtils.test.ts to verify this behavior for both numeric and string settings. I have no feedback to provide as there are no review comments.

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

Copy link
Copy Markdown
Contributor

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 updates the parseEditedValue function in settingsUtils.ts to reject non-finite numbers (such as NaN and ±Infinity) by replacing the Number.isNaN check with !Number.isFinite. This prevents issues where non-finite numbers are persisted as null in JSON. Additionally, comprehensive unit tests have been added in settingsUtils.test.ts to verify this behavior for various numeric and non-numeric inputs. There are no review comments, and I have no additional feedback to provide.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality labels Oct 26, 2026
@diegogodinezr

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown
Contributor

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 updates the parseEditedValue function in settingsUtils.ts to use Number.isFinite instead of Number.isNaN. This change ensures that non-finite numbers, such as Infinity, -Infinity, and overflow values like 1e309, are rejected and returned as null, preventing issues with JSON serialization. Comprehensive unit tests have been added in settingsUtils.test.ts to verify this behavior for various numeric, non-finite, and non-numeric inputs, as well as to ensure string settings are unaffected. There are no review comments, and I have no additional feedback to provide.

@DavidAPierce
DavidAPierce added this pull request to the merge queue Oct 26, 2026
Merged via the queue into google-gemini:main with commit 363a131 Oct 26, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality priority/p2 Important but can be addressed in a future release. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: numeric settings editor saves overflow values as null

2 participants