Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Unreleased

* bug fixes
* Downcase each word of multi-word authentication keys in failure flashes, so "Company Code" is not rendered as "company Code".

### 5.0.4 - 2026-05-08

* security fixes
Expand Down
7 changes: 4 additions & 3 deletions lib/devise/failure_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ def i18n_message(default = nil)
options[:default] = [message]
auth_keys = scope_class.authentication_keys
human_keys = (auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys).map { |key|
# TODO: Remove the fallback and just use `downcase_first` once we drop support for Rails 7.0.
human_key = scope_class.human_attribute_name(key)
human_key.respond_to?(:downcase_first) ? human_key.downcase_first : human_key[0].downcase + human_key[1..]
# Downcase the first letter of each word ("Company Code" => "company code")
# so a title-cased name does not become "company Code" mid-sentence.
# Skip a capital whose next letter is not lowercase, so "ID" and "E-Mail" stay intact.
scope_class.human_attribute_name(key).gsub(/(?<!\S)[[:upper:]](?=[[:lower:]])/, &:downcase)
}
options[:authentication_keys] = human_keys.join(I18n.t(:"support.array.words_connector"))
options = i18n_options(options)
Expand Down
8 changes: 8 additions & 0 deletions test/failure_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ def call_failure(env_params = {})
assert_equal 'Invalid email or password.', @request.flash[:alert]
end

test 'downcases each word of a multi-word authentication key' do
swap Devise, authentication_keys: [:loginid, :company_cd] do
I18n.backend.store_translations :en, activerecord: { attributes: { user: { loginid: 'Login ID', company_cd: 'Company Code' } } }
call_failure('warden' => OpenStruct.new(message: :invalid))
assert_equal 'Invalid login ID, company code or password.', @request.flash[:alert]
end
end

test 'humanizes the flash message' do
call_failure('warden' => OpenStruct.new(message: :invalid))
assert_equal @request.flash[:alert], @request.flash[:alert].humanize
Expand Down