{{ message }}
Repository navigation
Fix String#parameterize raising TypeError when separator is nil - #58324
Merged
Merged
Conversation
`parameterize` guards against a `nil` separator when squeezing duplicate
separators and trimming leading/trailing ones:
unless separator.nil? || separator.empty?
But the `gsub!` a few lines above passes the separator straight to
`String#gsub!`, so a `nil` separator raised `TypeError` before that guard
was ever reached, making the `separator.nil?` branch unreachable.
Treat a `nil` separator like an empty one, which is what the existing
guard already implies:
"Donald E. Knuth".parameterize(separator: nil) # => "donaldeknuth"
byroot
force-pushed
the
fix-parameterize-nil-separator
branch
from
August 1, 2026 08:14
4445604 to
6c6421a
Compare
byroot
added a commit
that referenced
this pull request
Aug 1, 2026
Fix `String#parameterize` raising `TypeError` when separator is nil
byroot
added a commit
that referenced
this pull request
Aug 1, 2026
Fix `String#parameterize` raising `TypeError` when separator is nil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
ActiveSupport::Inflector#parameterizecontains a guard that explicitly handles anilseparator:But three lines earlier the separator is passed straight to
String#gsub!:so a
nilseparator raises before the guard is ever reached, and theseparator.nil?branch is unreachable:Fix
Treat a
nilseparator like an empty one — which is exactly what the existing guard already implies — and drop the now-redundantseparator.nil?check:The alternative reading — that
nilwas never meant to be supported — would mean deleting theseparator.nil?branch instead. Making it work seemed like the smaller surprise for callers that pass a separator through from configuration or params, but happy to flip it to the removal if maintainers prefer that.Both
separator: nilandseparator: ""now go down the same path, so no behavior changes for any currently-working input.Tests
Added
separator: nilcases mirroring the existingseparator: ""tests, including thepreserve_case: truevariant, reusing the existingStringToParameterizeWithNoSeparatorandStringToParameterizePreserveCaseWithNoSeparatorfixtures.activesupport—string_ext_test.rb,inflector_test.rb,transliterate_test.rb: 645 runs, 3207 assertions, 0 failures, 0 errors. RuboCop clean.