Skip to content

Fix boolean query binding for flag-style parameters#10

Merged
bernardoforcillo merged 2 commits into
mainfrom
fix-bind-query-bool-flag-15309276825870585861
Jan 31, 2026
Merged

Fix boolean query binding for flag-style parameters#10
bernardoforcillo merged 2 commits into
mainfrom
fix-bind-query-bool-flag-15309276825870585861

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

This PR fixes an issue where boolean query parameters without values (flags) were causing binding errors.

Changes:

  • Modified context.go: Updated setField to handle empty strings for boolean values by setting them to true.

Verification:

  • Added a reproduction test case TestBindQueryFlag which confirmed the issue and verified the fix.
  • Ran all existing tests to ensure no regressions.

PR created automatically by Jules for task 15309276825870585861 started by @bernardoforcillo

When binding query parameters to a struct, if a boolean field's corresponding query parameter is present but empty (e.g. `?Flag`), it was previously causing a parsing error because `strconv.ParseBool` fails on empty strings.

This change modifies `setField` in `context.go` to treat empty strings as `true` for boolean fields, enabling flag-style query parameters. Explicit values like `?Flag=false` are still respected.
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

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

- Added `Mount` and `Any` methods to `App` and `Group` to easily register standard `http.Handler`s (like `grpc-gateway`) and support multi-method routes.
- Added `WrapHTTPHandler` utility.
- Fixed `BindQuery` to treat empty boolean params (flags) as `true` (e.g. `?Sector`).
- Added integration tests for mounting and boolean flags.

Co-authored-by: bernardoforcillo <28314446+bernardoforcillo@users.noreply.github.com>
@bernardoforcillo bernardoforcillo marked this pull request as ready for review January 31, 2026 07:07
@bernardoforcillo bernardoforcillo merged commit 089fe18 into main Jan 31, 2026
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