Skip to content

πŸ›‘οΈ Shield: Fix inconsistent boolean parsing for float strings#659

Merged
fderuiter merged 2 commits intomainfrom
shield-fix-parse-bool-float-142145209111035684
Feb 13, 2026
Merged

πŸ›‘οΈ Shield: Fix inconsistent boolean parsing for float strings#659
fderuiter merged 2 commits intomainfrom
shield-fix-parse-bool-float-142145209111035684

Conversation

@fderuiter
Copy link
Copy Markdown
Owner

πŸ›‘ Vulnerability: parse_bool was inconsistent when handling string representations of floating-point numbers. parse_bool("1.0") returned False because it wasn't in the optimized boolean set, whereas parse_bool(1.0) returned True. This could lead to data corruption when parsing numeric booleans from JSON APIs.

πŸ›‘οΈ Defense: Updated imednet/utils/validators.py to attempt float conversion for strings that look numeric (start with digit, sign, '.', 'n', or 'i'). This ensures that "1.0", "inf", "nan", etc. are parsed consistently with Python's float behavior.

πŸ”¬ Verification: Created tests/unit/test_parse_bool_float_str.py which verifies that:

  • "1.0", "1.000", "-1.0", "0.1", "1e1", "inf", "nan" return True.
  • "0.0", "0e1", "0.000" return False.
    Ran full test suite to ensure no regressions.

πŸ“Š Impact: Increases confidence in data parsing logic and prevents potential bugs in models that use parse_bool (e.g., JsonModel).


PR created automatically by Jules for task 142145209111035684 started by @fderuiter

- Add fallback to `float(v)` in `parse_bool` to correctly handle strings like "1.0", "inf", and "nan".
- Add optimized check to avoid performance penalty for common non-numeric strings.
- Add regression test `tests/unit/test_parse_bool_float_str.py`.

Impact: Fixes inconsistency where `parse_bool("1.0")` returned `False` while `parse_bool(1.0)` returned `True`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

- Add fallback to `float(v)` in `parse_bool` to correctly handle strings like "1.0", "inf", and "nan".
- Add optimized check to avoid performance penalty for common non-numeric strings.
- Add regression test `tests/unit/test_parse_bool_float_str.py`.
- Apply code formatting (black/isort) to test file.

Impact: Fixes inconsistency where `parse_bool("1.0")` returned `False` while `parse_bool(1.0)` returned `True`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@fderuiter fderuiter marked this pull request as ready for review February 13, 2026 19:35
@fderuiter fderuiter merged commit c859184 into main Feb 13, 2026
13 checks passed
@fderuiter fderuiter deleted the shield-fix-parse-bool-float-142145209111035684 branch February 13, 2026 19:35
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.

1 participant