Numeric types can be casted from strings with leading or trailing whitespace

Signed-off-by: Marcos Tapajós <tapajos@gmail.com>
This commit is contained in:
Christopher Durtschi 2011-02-26 01:33:16 -07:00 committed by Marcos Tapajós
parent 53b052f631
commit 755a0c813f
2 changed files with 16 additions and 1 deletions

View file

@ -79,7 +79,7 @@ module CouchRest
# Match numeric string
def typecast_to_numeric(value, method)
if value.respond_to?(:to_str)
if value.gsub(/,/, '.').gsub(/\.(?!\d*\Z)/, '').to_str =~ /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?|(?:\.\d+))\z/
if value.strip.gsub(/,/, '.').gsub(/\.(?!\d*\Z)/, '').to_str =~ /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?|(?:\.\d+))\z/
$1.send(method)
else
value