pg-hstore 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pg_hstore.rb +9 -21
  2. metadata +21 -5
@@ -1,6 +1,7 @@
1
1
  module PgHstore
2
2
  SINGLE_QUOTE = "'"
3
3
  DOUBLE_QUOTE = '"'
4
+ DOLLAR_QUOTE = '$$' # TODO not infallible
4
5
  HASHROCKET = '=>'
5
6
  COMMA = ','
6
7
 
@@ -12,7 +13,7 @@ module PgHstore
12
13
  # set symbolize_keys = false if you want string keys
13
14
  # thanks to https://github.com/engageis/activerecord-postgres-hstore for regexps!
14
15
  def PgHstore.load(hstore, symbolize_keys = true)
15
- hstore = unquote hstore, SINGLE_QUOTE
16
+ hstore = unquote hstore, DOLLAR_QUOTE
16
17
  hstore.scan(PAIR).inject({}) do |memo, (k, v)|
17
18
  k = unescape unquote(k, DOUBLE_QUOTE)
18
19
  k = k.to_sym if symbolize_keys
@@ -28,23 +29,15 @@ module PgHstore
28
29
  if v.nil?
29
30
  v = "NULL"
30
31
  else
31
- v = escape v
32
- unless for_parameter
33
- v = escape_single_quotes v
34
- end
35
- v = DOUBLE_QUOTE + v + DOUBLE_QUOTE
32
+ v = DOUBLE_QUOTE + escape(v) + DOUBLE_QUOTE
36
33
  end
37
- k = escape k
38
- unless for_parameter
39
- k = escape_single_quotes k
40
- end
41
- k = DOUBLE_QUOTE + k + DOUBLE_QUOTE
34
+ k = DOUBLE_QUOTE + escape(k) + DOUBLE_QUOTE
42
35
  [k, v].join HASHROCKET
43
- end.join(COMMA)
36
+ end.join COMMA
44
37
  if for_parameter
45
38
  memo
46
39
  else
47
- SINGLE_QUOTE + memo + SINGLE_QUOTE
40
+ DOLLAR_QUOTE + memo + DOLLAR_QUOTE
48
41
  end
49
42
  end
50
43
 
@@ -57,7 +50,8 @@ module PgHstore
57
50
 
58
51
  def PgHstore.unquote(string, quote_char)
59
52
  if string.start_with? quote_char
60
- string[1..-2]
53
+ l = quote_char.length
54
+ string[l..(-1-l)]
61
55
  else
62
56
  string
63
57
  end
@@ -65,7 +59,7 @@ module PgHstore
65
59
 
66
60
  ESCAPED_CHAR = /\\(.)/
67
61
  def PgHstore.unescape(literal)
68
- literal.gsub(ESCAPED_CHAR, '\1').gsub ESCAPED_SINGLE_QUOTE, SINGLE_QUOTE
62
+ literal.gsub ESCAPED_CHAR, '\1'
69
63
  end
70
64
 
71
65
  NON_ESCAPE_SLASH = '\\'
@@ -74,11 +68,5 @@ module PgHstore
74
68
  def PgHstore.escape(string)
75
69
  string.to_s.gsub(NON_ESCAPE_SLASH) {ESCAPED_SLASH}.gsub DOUBLE_QUOTE, ESCAPED_DOUBLE_QUOTE
76
70
  end
77
-
78
- ESCAPED_SINGLE_QUOTE = "''"
79
- def PgHstore.escape_single_quotes(literal)
80
- literal.to_s.gsub SINGLE_QUOTE, ESCAPED_SINGLE_QUOTE
81
- end
82
-
83
71
  end
84
72
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg-hstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -17,17 +17,33 @@ dependencies:
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ~>
20
+ - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
- version: 2.5.0
22
+ version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - ~>
28
+ - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
- version: 2.5.0
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: pg
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
31
47
  description: postgresql hstore parser/deparser - provides PgHstore.dump and PgHstore.load
32
48
  (aka parse)
33
49
  email: