pump 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -1
- data/Gemfile +1 -0
- data/gemfiles/activesupport-3-2 +1 -1
- data/gemfiles/activesupport-4 +1 -1
- data/lib/pump/version.rb +1 -1
- data/lib/pump/xml.rb +30 -0
- data/lib/pump/xml/value.rb +5 -1
- data/pump.gemspec +0 -1
- data/spec/pump/xml/value_spec.rb +8 -2
- data/spec/pump/xml_spec.rb +8 -0
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b930e2c3f51715a45b93e926ee3f1919d5958a9
|
4
|
+
data.tar.gz: 9deabda70b6c60e6829faa5303ed8c155b87a3d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27f537da752f98e0a036c193f9424f9dc55face76e0689acfbff4a73584a4ada0689e89eb741cf13a32f3f36ad92b66c337b4c845ea4bf4d02eb70d17630f5e0
|
7
|
+
data.tar.gz: 005b91800f465e6f14977fc1e203e41410ec4d26120138842ca7bd44d4e5312d2287a9d68b325ff7784d3b4e0fb26909e5aef51e2db7a079da92d5544a05c645
|
data/CHANGES.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](http://github.com/yolk/pump/compare/v0.6.
|
3
|
+
[full changelog](http://github.com/yolk/pump/compare/v0.6.5...master)
|
4
|
+
|
5
|
+
### 0.6.5 / 2014-07-03
|
6
|
+
|
7
|
+
[full changelog](http://github.com/yolk/valvat/compare/v0.6.4...v0.6.5)
|
8
|
+
|
9
|
+
* XML: Remove ilegal chars from string values
|
4
10
|
|
5
11
|
### 0.6.4 / 2013-11-08
|
6
12
|
|
data/Gemfile
CHANGED
data/gemfiles/activesupport-3-2
CHANGED
data/gemfiles/activesupport-4
CHANGED
data/lib/pump/version.rb
CHANGED
data/lib/pump/xml.rb
CHANGED
@@ -61,6 +61,36 @@ module Pump
|
|
61
61
|
def add_instruct?
|
62
62
|
encoder_options.has_key?(:instruct) ? encoder_options[:instruct] : true
|
63
63
|
end
|
64
|
+
|
65
|
+
VALID_CHAR = [
|
66
|
+
0x9, 0xA, 0xD,
|
67
|
+
(0x20..0xD7FF),
|
68
|
+
(0xE000..0xFFFD),
|
69
|
+
(0x10000..0x10FFFF)
|
70
|
+
]
|
71
|
+
|
72
|
+
VALID_XML_CHARS = Regexp.new('^['+
|
73
|
+
VALID_CHAR.map { |item|
|
74
|
+
case item
|
75
|
+
when Fixnum
|
76
|
+
[item].pack('U').force_encoding('utf-8')
|
77
|
+
when Range
|
78
|
+
[item.first, '-'.ord, item.last].pack('UUU').force_encoding('utf-8')
|
79
|
+
end
|
80
|
+
}.join +
|
81
|
+
']*$')
|
82
|
+
|
83
|
+
def remove_ilegal_chars(string)
|
84
|
+
return string if !string.is_a?(String) || string =~ VALID_XML_CHARS
|
85
|
+
out = ""
|
86
|
+
string.chars.each do |c|
|
87
|
+
case c.ord
|
88
|
+
when *VALID_CHAR
|
89
|
+
out << c
|
90
|
+
end
|
91
|
+
end
|
92
|
+
out
|
93
|
+
end
|
64
94
|
end
|
65
95
|
end
|
66
96
|
|
data/lib/pump/xml/value.rb
CHANGED
@@ -10,7 +10,7 @@ module Pump
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_s(plain_path=nil)
|
13
|
-
"\#{#{plain_path || plain}#{cast}}"
|
13
|
+
"\#{#{remove_ilegal_chars}#{plain_path || plain}#{cast}}"
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
@@ -22,6 +22,10 @@ module Pump
|
|
22
22
|
'.to_s.encode(:xml => :text)'
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
def remove_ilegal_chars
|
27
|
+
"remove_ilegal_chars " if !options[:typecast] && !options[:xmlsafe]
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
data/pump.gemspec
CHANGED
data/spec/pump/xml/value_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Pump::Xml::Value do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "#to_s" do
|
18
|
-
its(:to_s) { should eql("\#{object.method_name.to_s.encode(:xml => :text)}") }
|
18
|
+
its(:to_s) { should eql("\#{remove_ilegal_chars object.method_name.to_s.encode(:xml => :text)}") }
|
19
19
|
|
20
20
|
context "with option :xmlsafe => true" do
|
21
21
|
subject { Pump::Xml::Value.new("method_name", {}, [], :xmlsafe => true) }
|
@@ -23,9 +23,15 @@ describe Pump::Xml::Value do
|
|
23
23
|
its(:to_s) { should eql("\#{object.method_name}") }
|
24
24
|
end
|
25
25
|
|
26
|
+
context "with option :typecast => :xmlschema" do
|
27
|
+
subject { Pump::Xml::Value.new("method_name", {}, [], :typecast => :xmlschema) }
|
28
|
+
|
29
|
+
its(:to_s) { should eql("\#{object.method_name.xmlschema}") }
|
30
|
+
end
|
31
|
+
|
26
32
|
context "with path name" do
|
27
33
|
it do
|
28
|
-
subject.to_s('custom_path').should eql("\#{custom_path.to_s.encode(:xml => :text)}")
|
34
|
+
subject.to_s('custom_path').should eql("\#{remove_ilegal_chars custom_path.to_s.encode(:xml => :text)}")
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
data/spec/pump/xml_spec.rb
CHANGED
@@ -14,6 +14,14 @@ describe Pump::Xml do
|
|
14
14
|
xml.encode(person).should eql("#{XML_INSTRUCT}<person>\n <name>Benny</name>\n</person>\n")
|
15
15
|
end
|
16
16
|
|
17
|
+
context "with ilegal chars" do
|
18
|
+
let(:person) { Struct.new(:name, :age, :last_name).new("Benny \u001APenny", 9, "Hellman") }
|
19
|
+
|
20
|
+
it "returns xml string" do
|
21
|
+
xml.encode(person).should eql("#{XML_INSTRUCT}<person>\n <name>Benny Penny</name>\n</person>\n")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
context "with array" do
|
18
26
|
|
19
27
|
context "with one entry" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Munz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.12.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard-rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2.2.2
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2.2.2
|
69
55
|
description: Fast but inflexible XML and JSON encoding for ruby objects.
|
70
56
|
email:
|
71
57
|
- sebastian@yo.lk
|