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.
- data/lib/ensure_valid_encoding/version.rb +1 -1
- data/lib/ensure_valid_encoding.rb +11 -14
- metadata +2 -2
@@ -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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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.
|
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-
|
12
|
+
date: 2012-07-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|