right_support 2.8.10 → 2.8.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -11,7 +11,7 @@ group :optional do
11
11
  gem "simple_uuid", "~> 0.2", :require => nil
12
12
  gem "uuid", "~> 2.3", :require => nil
13
13
  gem "yajl-ruby", "~> 1.1"
14
- gem "iconv"
14
+ gem "iconv", :platforms => :ruby_18
15
15
  end
16
16
 
17
17
  # Gems used during test and development of RightSupport.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.8.10
1
+ 2.8.11
@@ -22,7 +22,6 @@
22
22
 
23
23
  require 'time'
24
24
  require 'date'
25
- require 'iconv'
26
25
 
27
26
  module RightSupport::Data
28
27
  # Utility class that implements true, lossless Ruby-to-JSON serialization.
@@ -142,14 +141,47 @@ module RightSupport::Data
142
141
 
143
142
  protected
144
143
 
144
+ if RUBY_VERSION =~ /^1\.8/ && require_succeeds?('iconv')
145
+ # Given a String, replace invalid UTF-8 character sequences and return a string with valid
146
+ # UTF-8 encoding. This requires the iconv gem to be present if running under Ruby 1.8.
147
+ #
148
+ # @param [String] dirty the string to be scrubbed
149
+ # @return [String]
150
+ def scrub_string(dirty)
151
+ iconv = Iconv.new('UTF-8//IGNORE', 'UTF-8')
152
+ iconv.iconv(dirty)
153
+ end
154
+ elsif RUBY_VERSION !~ /^1\.8/
155
+ # Given a String, replace invalid UTF-8 character sequences and return a string with valid
156
+ # UTF-8 encoding. This requires the iconv gem to be present if running under Ruby 1.8.
157
+ #
158
+ # @param [String] dirty the string to be scrubbed
159
+ # @return [String]
160
+ def scrub_string(dirty)
161
+ dirty.dup.force_encoding(Encoding::BINARY).encode(Encoding::UTF_8,
162
+ :invalid => :replace,
163
+ :undef => :replace,
164
+ :replace => '')
165
+ end
166
+ else
167
+ warn "Cannot deal with invalid UTF-8 codepoints; install iconv or upgrade to Ruby > 1.8"
168
+ # Given a String, replace invalid UTF-8 character sequences and return a string with valid
169
+ # UTF-8 encoding. This requires the iconv gem to be present if running under Ruby 1.8.
170
+ #
171
+ # @param [String] dirty the string to be scrubbed
172
+ # @return [String]
173
+ def scrub_string(dirty)
174
+ dirty
175
+ end
176
+ end
177
+
145
178
  # Given an Object, transform it into a JSONish Ruby structure.
146
179
  # @param [Object] object any Ruby object
147
180
  # @return [Object] JSONish representation of input object
148
181
  def object_to_jsonish(object)
149
- iconv = Iconv.new('UTF-8//IGNORE', 'UTF-8')
150
182
  case object
151
183
  when String
152
- object = iconv.iconv(object)
184
+ object = scrub_string(object)
153
185
  if (object =~ /^:/ ) || (object =~ TIME_PATTERN)
154
186
  # Strings that look like a Symbol or Time must be object-escaped.
155
187
  {@marker => String.name,
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "right_support"
8
- s.version = "2.8.10"
8
+ s.version = "2.8.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tony Spataro", "Sergey Sergyenko", "Ryan Williamson", "Lee Kirchhoff", "Alexey Karpik", "Scott Messier"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
4
+ hash: 57
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 8
9
- - 10
10
- version: 2.8.10
9
+ - 11
10
+ version: 2.8.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro