coder 0.2.1 → 0.3.0
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/coder.gemspec +1 -0
- data/lib/coder.rb +2 -0
- data/lib/coder/ext/active_support.rb +12 -0
- data/lib/coder/version.rb +1 -1
- data/spec/ext/active_support_spec.rb +18 -0
- metadata +21 -2
data/coder.gemspec
CHANGED
data/lib/coder.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'active_support/json/encoding'
|
2
|
+
|
3
|
+
module ActiveSupport::JSON::Encoding
|
4
|
+
def self.escape(string)
|
5
|
+
json = Coder.force_encoding!(Coder.clean(string), 'binary')
|
6
|
+
json.gsub!(escape_regex) { |s| ESCAPED_CHARS[s] }
|
7
|
+
json.gsub! /([\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3})+/nx do |s|
|
8
|
+
s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/n, '\\\\u\&')
|
9
|
+
end
|
10
|
+
Coder.force_encoding!(%("#{json}"))
|
11
|
+
end
|
12
|
+
end
|
data/lib/coder/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'coder/ext/active_support'
|
4
|
+
|
5
|
+
describe ActiveSupport::JSON do
|
6
|
+
it 'still escapes unicode properly' do
|
7
|
+
ActiveSupport::JSON.encode('€2.99').should be == '"\\u20ac2.99"'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'still encodes unicode properly' do
|
11
|
+
ActiveSupport::JSON.encode('€2.99').encoding.should be == Encoding::UTF_8
|
12
|
+
end if defined? Encoding::UTF_8
|
13
|
+
|
14
|
+
it 'actually uses Coder internally' do
|
15
|
+
Coder.should_receive(:clean).with('€2.99').and_return('€2.99')
|
16
|
+
ActiveSupport::JSON.encode('€2.99')
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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-09-
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '2.11'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.2'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.2'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rake
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,9 +83,11 @@ files:
|
|
67
83
|
- lib/coder/cleaner/simple/byte_buffer.rb
|
68
84
|
- lib/coder/cleaner/simple/encodings.rb
|
69
85
|
- lib/coder/error.rb
|
86
|
+
- lib/coder/ext/active_support.rb
|
70
87
|
- lib/coder/version.rb
|
71
88
|
- spec/coder/cleaner_spec.rb
|
72
89
|
- spec/coder_spec.rb
|
90
|
+
- spec/ext/active_support_spec.rb
|
73
91
|
- spec/spec_helper.rb
|
74
92
|
- spec/support/binary_matcher.rb
|
75
93
|
- spec/support/clean_helpers.rb
|
@@ -100,6 +118,7 @@ summary: library to handle encodings
|
|
100
118
|
test_files:
|
101
119
|
- spec/coder/cleaner_spec.rb
|
102
120
|
- spec/coder_spec.rb
|
121
|
+
- spec/ext/active_support_spec.rb
|
103
122
|
- spec/spec_helper.rb
|
104
123
|
- spec/support/binary_matcher.rb
|
105
124
|
- spec/support/clean_helpers.rb
|