Repository navigation
Fix strip_whitespace not working with group conditions - #1635
scarroll32 with Copilot wants to merge 3 commits into
Conversation
Co-authored-by: scarroll32 <11340230+scarroll32@users.noreply.github.com>
|
Note Comment from Claude (Claude Code), acting on behalf of @scarroll32. Closing as part of clearing the PR backlog ahead of 5.0.0 (#1640). This is one of a batch of PRs opened by the Copilot coding agent in September 2025. They have aged out: The underlying issue stays open. Nothing is being dismissed on the merits — the bug reports behind these PRs are still valid and still wanted. What's being retired is a batch of stale machine-generated branches that cost more to salvage than to redo. If you're affected by the underlying issue, the most useful contribution is a PR with a failing spec that reproduces it against current |
Problem
The
strip_whitespaceoption was not working for group conditions in Ransack searches. While whitespace stripping worked correctly for top-level conditions, it was ignored when using grouped conditions with theg:parameter.For example, this search would not strip whitespace from the values:
The values
" John "and" john@example.com "would retain their leading/trailing whitespace even whenstrip_whitespacewas enabled globally or passed as an option.Root Cause
The whitespace stripping logic was only implemented in
Search#initializeat the top level. When group conditions were processed, they went through theGrouping#buildmethod which didn't have access to thestrip_whitespaceoption, so nested conditions never had their whitespace stripped.Solution
This fix implements a minimal change to pass the
strip_whitespaceoption down to nested groupings:Added
strip_whitespaceattribute to Context: The baseContextclass now stores the strip_whitespace setting so it's available to all nested operations.Set context strip_whitespace in Search: The
Search#initializemethod now sets thestrip_whitespaceoption on the context after determining it from options or global config.Enhanced Grouping#build with whitespace stripping: The
Grouping#buildmethod now applies whitespace stripping recursively whenstrip_whitespaceis enabled.Added recursive helper method: A new
strip_whitespace_from_paramsmethod handles stripping whitespace from nested Hash, Array, and String structures.Testing
strip_whitespace: trueandstrip_whitespace: falsescenarios for group conditionsExample
After this fix, the following now works as expected:
The fix maintains full backward compatibility and respects both global
Ransack.options[:strip_whitespace]configuration and per-searchstrip_whitespace: falseoptions.Fixes the issue where group conditions didn't respect the strip_whitespace setting.
Original prompt
Fixes #1414
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.