diff options
author | Aaron Stone <aaron@serendipity.cx> | 2013-01-23 01:05:23 -0800 |
---|---|---|
committer | Aaron Stone <aaron@serendipity.cx> | 2013-01-31 09:01:20 -0800 |
commit | 4b005fb371c2e7af80df7da63be94509b1db038c (patch) | |
tree | cd4ecad2d5664b4ab5f4411a2141a32164e0d769 /activerecord/lib | |
parent | ee4a2bb23d46ee3e644293ba59b70fa7ecb3f7eb (diff) | |
download | rails-4b005fb371c2e7af80df7da63be94509b1db038c.tar.gz rails-4b005fb371c2e7af80df7da63be94509b1db038c.tar.bz2 rails-4b005fb371c2e7af80df7da63be94509b1db038c.zip |
DATABASE_URL parsing should turn numeric strings into numeric types, and
the strings true and false into boolean types, in order to match how
YAML would parse the same values from database.yml and prevent
unexpected type errors in the database adapters.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/connection_specification.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index 09250d3c01..d7cd34df22 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -62,6 +62,10 @@ module ActiveRecord ConnectionSpecification.new(spec, adapter_method) end + # For DATABASE_URL, accept a limited concept of ints and floats + SIMPLE_INT = /^\d+$/ + SIMPLE_FLOAT = /^\d+\.\d+$/ + def connection_url_to_hash(url) # :nodoc: config = URI.parse url adapter = config.scheme @@ -77,6 +81,21 @@ module ActiveRecord spec.map { |key,value| spec[key] = uri_parser.unescape(value) if value.is_a?(String) } if config.query options = Hash[config.query.split("&").map{ |pair| pair.split("=") }].symbolize_keys + # If anything looks numeric, make it numeric (e.g. pool count, timeout values, etc.) + options.map do |key,value| + options[key] = case value + when SIMPLE_INT + value.to_i + when SIMPLE_FLOAT + value.to_f + when 'true' + true + when 'false' + false + else + value + end + end spec.merge!(options) end spec |