ensure_valid_encoding 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module EnsureValidEncoding
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -50,20 +50,17 @@ module EnsureValidEncoding
50
50
  else
51
51
  # :replace => :invalid,
52
52
  # actually need to go through chars to replace bad ones
53
- return str.chars.collect do |c|
54
- if c.valid_encoding?
55
- c
56
- else
57
- options[:replace] || (
58
- # UTF-8 for unicode replacement char, encode in
59
- # encoding of input string, using '?' as a fallback where
60
- # it can't be (which should be non-unicode encodings)
61
- "\uFFFD".force_encoding("UTF-8").encode( str.encoding,
62
- :undef => :replace,
63
- :replace => '?' )
64
- )
65
- end
66
- end.join
53
+
54
+ replacement_char = options[:replace] || (
55
+ # UTF-8 for unicode replacement char \uFFFD, encode in
56
+ # encoding of input string, using '?' as a fallback where
57
+ # it can't be (which should be non-unicode encodings)
58
+ "\xEF\xBF\xBD".force_encoding("UTF-8").encode( str.encoding,
59
+ :undef => :replace,
60
+ :replace => '?' )
61
+ )
62
+
63
+ return str.chars.collect { |c| c.valid_encoding? ? c : replacement_char }.join
67
64
  end
68
65
  end
69
66
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensure_valid_encoding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000 Z
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: