
dm-validations stringy regexp validations fail scientific notation
Reported by Shane Hanna | July 31st, 2009 @ 12:37 AM | in 0.10.0
I have a couple Float values in my database. The validations in dm-validations kept giving me validations from time to time. I tracked it down to the regexps in dm-validations.
http://github.com/datamapper/dm-more/blob/2cb0369f1853ed4aff32a3d3a...
The to_s here (line 20) will sometimes be in scientific notation. For example -0.00004 (-4.0e-05) so all the regexp validations futher down (~line 45 onwards) fail.
http://github.com/datamapper/dm-more/blob/2cb0369f1853ed4aff32a3d3a...
The two fixes I can think of are converting everything to BigDecimal and using .to_s('F') or adding an exponent alternative to each regexp. I'm happy to submit a patch for either (or if you have a better idea).
Comments and changes to this ticket
-
Dan Kubb (dkubb) July 31st, 2009 @ 02:08 PM
- State changed from new to confirmed
I would say use the approach that will result in the least amount of complex code. Adding an extra regexp to each of those seems like it would result in alot more code than using BigDecimal#to_s like you said. If you would like to submit a patch for this I would gladly accept it.
-
Shane Hanna August 2nd, 2009 @ 10:27 PM
http://github.com/shanna/dm-more/tree/scientific-notation-fix
http://github.com/shanna/dm-more/commit/2113ce53b538a9650395f58c4ff...Merged scientific-notation-fix branch into next as well since I don't know how you guys expect patches to be submitted. I hope that's ok.
-
Martin Gamsjaeger (snusnu) August 3rd, 2009 @ 07:04 AM
- Assigned user set to Martin Gamsjaeger (snusnu)
- State changed from confirmed to accepted
- Milestone set to 0.10.0
-
Dan Kubb (dkubb) August 3rd, 2009 @ 10:18 AM
- State changed from accepted to resolved
(from [0c58330f1ee3b27978fec1e3331c1b68417a738a]) [dm-validations] Avoid scientific notation in Float.to_s
- This allows precision and scale regexps to work in case the float value is represented in scientific notation internally.
[#996 state:resolved] http://github.com/datamapper/dm-more/commit/0c58330f1ee3b27978fec1e...
-
Martin Gamsjaeger (snusnu) August 3rd, 2009 @ 10:24 AM
Shane
I applied your patch with a simple spec that was failing before, and passes with your patch. Thx!
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Tags
Referenced by
-
996 dm-validations stringy regexp validations fail scientific notation [#996 state:resolved] http://github.com/datamapper/dm-mo...