heartcombo / simple_form

Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup.
http://blog.plataformatec.com.br/tag/simple_form
MIT License
8.21k stars 1.31k forks source link

Rails 7.1 updated password validation changed rendering of password inputs #1825

Closed arg closed 2 months ago

arg commented 9 months ago

I'm not entirely sure who I should report this issue to, but it looks like has_secure_password change made in https://github.com/rails/rails/pull/47708 partially broke rendering of password inputs, as it doesn't use the regular validates_length_of anymore, but instead goes with a custom validation. So the following snippet renders different output in Rails 7.0 and Rails 7.1

class User < ApplicationRecord
  # has email attribute
  has_secure_password
end
...
@user = User.new
...
= simple_form_for @user, url: login_path, method: :post do |f|
  = f.input :email
  = f.input :password

Environment

Current behavior

<form class="simple_form form-vertical new_user" id="new_user" novalidate="novalidate" action="/login" accept-charset="UTF-8" method="post">
  <div class="field">
    <label for="user_email">Email</label>
    <input maxlength="100" type="email" size="100" name="user[email]" id="user_email">
  </div>
  <div class="field">
    <label for="user_password">Password</label>
    <input type="password" name="user[password]" id="user_password">
  </div>
</form>

Expected behavior

Notice the maxlength="72" and size="72" attributes of password input

<form class="simple_form form-vertical new_user" id="new_user" novalidate="novalidate" action="/login" accept-charset="UTF-8" method="post">
  <div class="field">
    <label for="user_email">Email</label>
    <input maxlength="100" type="email" size="100" name="user[email]" id="user_email">
  </div>
  <div class="field">
    <label for="user_password">Password</label>
    <input maxlength="72" size="72" type="password" name="user[password]" id="user_password">
  </div>
</form>

Of course, as a workaround we can just specify maxlength for every password, password confirmation and password challenge input.

nashby commented 2 months ago

Hey @arg! Nothing much can be done about it, unfortunately. Yeah, technically we could check somehow if has_secure_password or bcrypt is used and apply limits, but with custom validation, we can't do it automatically as before. I think setting it manually is an acceptable workaround, and it's simple enough.