Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

The replace_first filter was crashing when the string to be replaced was nil. This happened when an undefined variable was used as an argument to the filter. This change adds a nil check to the replace_first function to prevent the crash and return the input string unmodified, which aligns with the behavior of other filters.

When `replace_first` is called with a `nil` value as the string to be replaced, it raises an `ArgumentError`.

This commit fixes this issue by adding a check for `nil` and returning the input string unchanged in that case, which is the expected behavior.
When `replace_first` is called with a `nil` value as the string to be replaced, it should behave like replacing with an empty string.

This commit fixes this issue by using `to_str` to convert the `nil` value to an empty string before passing it to `String.replace`.
@edgurgel edgurgel marked this pull request as ready for review August 9, 2025 01:46
When `replace_first` is called with a `nil` value as the string to be replaced, it should behave like replacing with an empty string.

This commit fixes this issue by using `to_str` to convert the `nil` value to an empty string before passing it to `String.replace`.
@edgurgel edgurgel merged commit 194335a into main Aug 9, 2025
6 checks passed
@edgurgel edgurgel deleted the fix-replace-first-nil-arg branch August 9, 2025 04:46
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.

2 participants