Skip to content

Instantly share code, notes, and snippets.

@AquaGeek
Created May 14, 2011 02:17
Show Gist options
  • Save AquaGeek/971644 to your computer and use it in GitHub Desktop.
Save AquaGeek/971644 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #3271
From d98ced094bf5f8dcb6c181eb3c020611e2b70ae9 Mon Sep 17 00:00:00 2001
From: Alex Shulgin <[email protected]>
Date: Wed, 23 Mar 2011 18:52:00 +0200
Subject: [PATCH] Fix bitstrings handling in PostgreSQL adapter.
---
.../connection_adapters/postgresql_adapter.rb | 9 +++++----
.../cases/adapters/postgresql/datatype_test.rb | 2 +-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 5a830a5..fee802e 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -344,10 +344,11 @@ module ActiveRecord
when 'bytea' then "'#{escape_bytea(value)}'"
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
- end
+ # We should not pretend that we can guess the base (binary
+ # vs. hexadecimal) by just examining the value string.
+ #
+ # See https://rails.lighthouseapp.com/projects/8994/tickets/3271
+ "B'#{quote_string(value)}'"
else
super
end
diff --git a/activerecord/test/cases/adapters/postgresql/datatype_test.rb b/activerecord/test/cases/adapters/postgresql/datatype_test.rb
index 5bb8fa2..4ac63dc 100644
--- a/activerecord/test/cases/adapters/postgresql/datatype_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/datatype_test.rb
@@ -190,7 +190,7 @@ class PostgresqlDataTypeTest < ActiveRecord::TestCase
def test_update_bit_string
new_bit_string = '11111111'
- new_bit_string_varying = 'FF'
+ new_bit_string_varying = '11111111'
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
--
1.7.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment