Skip to content

Commit

Permalink
Avoid creating multiple regexp objects
Browse files Browse the repository at this point in the history
The check is slightly different but should work for our purposes here.

Using `end_with?(mapping)` to keep a similar check doesn't work because
some Ruby versions include "did you mean", which make the error message
look something like this:

    NameError: uninitialized constant StringInput

        at.const_get(mapping)
          ^^^^^^^^^^
    Did you mean?  StringInputTest

The regexp check worked because it was matching the end of the line, not
end of string, with `$`, so it'd match the first line of the error
message always.
  • Loading branch information
carlosantoniodasilva committed May 24, 2024
1 parent ae12516 commit ba02a8b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

* Revert "Speed up input mapping lookup by avoiding rescuing exceptions" from v5.3.0, it caused a regression on dev/test environments with custom inputs.
* Try a slightly different approach to input lookups, without relying on regexp, to see if that helps with performance as originally intended.
* Add support to Ruby 3.3. (no changes required.)

## 5.3.0
Expand Down
2 changes: 1 addition & 1 deletion lib/simple_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def attempt_mapping(mapping, at)
begin
at.const_get(mapping)
rescue NameError => e
raise if e.message !~ /#{mapping}$/
raise unless e.message.include?(mapping)
end
end

Expand Down

0 comments on commit ba02a8b

Please sign in to comment.