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 b8e2664 commit 01a2ac12b90691315dec7792f98f895819c53e06 @kennyj kennyj committed Nov 13, 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*
+
* Added Statement Cache to allow the caching of a single statement. The cache works by
duping the relation returned from yielding a statement, which allows skipping the AST
building phase for following executes. The cache returns results in array format.
@@ -28,8 +28,10 @@ def string_to_time(string)
def string_to_bit(value)
case value
- when /^[01]*$/ then value # Bit-string notation
- when /^[0-9A-F]*$/i then value.hex.to_s(2) # Hexadecimal notation
+ when /^0x/i
+ value[2..-1].hex.to_s(2) # Hexadecimal notation
+ else
+ value # Bit-string notation
end
end
@@ -545,14 +545,20 @@ 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
assert @first_bit_string.reload
assert_equal @first_bit_string.bit_string, new_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

0 comments on commit 01a2ac1

Please sign in to comment.