jeremyevans-postgres-pr 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ module Postgres::Conversion
4
4
  # For encoding rules see:
5
5
  # http://www.postgresql.org/docs/7.4/static/datatype-binary.html
6
6
  #
7
+ # The historical bytea escape format is always used, for maximum compatibility.
7
8
  def encode_bytea(str)
8
9
  # each_byte used instead of [] for 1.9 compatibility
9
10
  str.gsub(/[\000-\037\047\134\177-\377]/){|b| "\\#{sprintf('%o', b.each_byte{|x| break x}).rjust(3, '0')}"}
@@ -14,9 +15,16 @@ module Postgres::Conversion
14
15
  # For decoding rules see:
15
16
  # http://www.postgresql.org/docs/7.4/static/datatype-binary.html
16
17
  #
18
+ # Supports both the historical escape format and the new 9.0+ hex format.
17
19
  def decode_bytea(str)
18
- str.gsub(/\\(\\|'|[0-3][0-7][0-7])/) {|s|
19
- if s.size == 2 then s[1,1] else s[1,3].oct.chr end
20
- }
20
+ if str =~ /\A\\x/
21
+ # PostgreSQL 9.0+ bytea hex format
22
+ str[2..-1].gsub(/(..)/){|s| s.to_i(16).chr}
23
+ else
24
+ # Historical PostgreSQL bytea escape format
25
+ str.gsub(/\\(\\|'|[0-3][0-7][0-7])/) {|s|
26
+ if s.size == 2 then s[1,1] else s[1,3].oct.chr end
27
+ }
28
+ end
21
29
  end
22
30
  end
@@ -1,3 +1,3 @@
1
1
  module PostgresPR
2
- Version = "0.6.3"
2
+ Version = "0.6.4"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeremyevans-postgres-pr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Evans
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-15 00:00:00 -07:00
18
+ date: 2010-10-05 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21