This project is archived and is in readonly mode.
validates_length_of should exclude last member of an end-excluding range
Reported by jed | July 31st, 2009 @ 07:07 PM
If provided with an end-excluding range, validates_length_of will not exclude the last member of the range.
In the code below, the current behavior of validates_length_of will consider the first_name attribute valid if it is 61 characters long.
class Person << ActiveRecord::Base
validates_length_of :first_name, :in => 3...61
end
The attached patch corrects this by properly excluding the last member of an exclusive range.
Comments and changes to this ticket
-
jed August 2nd, 2009 @ 03:07 PM
- no changes were found...
-
José Valim August 8th, 2009 @ 03:02 PM
- Tag changed from patch, validates_length_of, validations to bugmash, patch, validates_length_of, validations
-
Adam Keys August 8th, 2009 @ 06:43 PM
The patch above appears to apply to master, unless I'm missing something. I've attached a patch that applies to 2-3-stable and verified it.
-
David Trasbo August 8th, 2009 @ 06:56 PM
+1
Patch is applied cleanly to edge and all tests are passing.
-
José Valim August 8th, 2009 @ 07:37 PM
- State changed from new to incomplete
Using range.min and range.max iterates through the whole collection. The patch should do something like:
min = range.begin max = range.end max -= 1 if range.exclude_end?
-
José Valim August 8th, 2009 @ 11:32 PM
- State changed from incomplete to resolved
- Tag changed from bugmash, patch, validates_length_of, validations to patch, validates_length_of, validations
-
Repository August 9th, 2009 @ 05:18 AM
(from [5632b36701ad9514d596c558877cd74c14c1d54b]) Fix exclusive range patch to use begin/end instead of min/max. [#2981 status:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
Signed-off-by: Pratik Naik pratiknaik@gmail.com
http://github.com/rails/rails/commit/5632b36701ad9514d596c558877cd7...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 2981 validates_length_of should exclude last member of an end-excluding range (from [5632b36701ad9514d596c558877cd74c14c1d54b]) Fix exc...