Permalink
Browse files

Fix #7619. 0x prefix must be added when assigning hexadecimal string …

…into bit column in Postgresql, because solving ambiguity.
  • Loading branch information...
1 parent 7864f83 commit 7d244df9b0108dc4309fbd07206262f7690dc959 @kennyj committed Sep 15, 2012
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* `0x` prefix must be added when assigning hexadecimal string into `bit` column in PostgreSQL.
+
+ *kennyj*
+
* Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
*Alexis Bernard*
@@ -54,8 +54,8 @@ def quote(value, column = nil) #:nodoc:
when 'xml' then "xml '#{quote_string(value)}'"
when /^bit/
case value
- when /^[01]*$/ then "B'#{value}'" # Bit-string notation
- when /^[0-9A-F]*$/i then "X'#{value}'" # Hexadecimal notation
+ when /^0x/i then "X'#{value[2..-1]}'" # Hexadecimal notation
+ else "B'#{value}'" # Bit-string notation
end
else
super
@@ -235,7 +235,7 @@ def test_update_network_address
def test_update_bit_string
new_bit_string = '11111111'
- new_bit_string_varying = 'FF'
+ new_bit_string_varying = '0xFF'
assert @first_bit_string.bit_string = new_bit_string
assert @first_bit_string.bit_string_varying = new_bit_string_varying
assert @first_bit_string.save
@@ -244,6 +244,12 @@ def test_update_bit_string
assert_equal @first_bit_string.bit_string, @first_bit_string.bit_string_varying
end
+ def test_invalid_hex_string
+ new_bit_string = 'FF'
+ @first_bit_string.bit_string = new_bit_string
+ assert_raise(ActiveRecord::StatementInvalid) { assert @first_bit_string.save }
+ end
+
def test_update_oid
new_value = 567890
assert @first_oid.obj_id = new_value

0 comments on commit 7d244df

Please sign in to comment.