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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27f8a3e058da84aed35138707b6be1836abb45e8
4
- data.tar.gz: 7d4e25c6424008b13f67aef733eb6bddbc586afd
3
+ metadata.gz: 6b930e2c3f51715a45b93e926ee3f1919d5958a9
4
+ data.tar.gz: 9deabda70b6c60e6829faa5303ed8c155b87a3d8
5
5
  SHA512:
6
- metadata.gz: dbede9b7e563335f30ed7682644ce43eb974dc21ce2bae10257d44b9520cd29a63523f3b2e87f9b61bc9a662d3ec8bf83ec7d53d8da08a8e0c5b7c86f61f368e
7
- data.tar.gz: 32020a5f3bc48ca51f9cb1e2b6872547e8dbfff045607549ce431076a7d11d503e1369714d5b99f7f6eb4a285c95df495147002265b3a6036ffaccbfd41e393d
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.4...master)
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
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in pump.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'guard-rspec', '~>4.0'
6
7
  gem 'rb-fsevent' if RUBY_PLATFORM.include?("x86_64-darwin")
@@ -3,5 +3,5 @@ source "http://rubygems.org"
3
3
  gem "activemodel", "3.2.13"
4
4
  gem "oj"
5
5
 
6
- gem 'rspec', '>= 2.4.0'
6
+ gem 'rspec', '>= 2.14'
7
7
  gem 'rake'
@@ -3,5 +3,5 @@ source "http://rubygems.org"
3
3
  gem "activemodel", "4.0"
4
4
  gem "oj"
5
5
 
6
- gem 'rspec', '>= 2.4.0'
6
+ gem 'rspec', '>= 2.14'
7
7
  gem 'rake'
@@ -1,3 +1,3 @@
1
1
  module Pump
2
- VERSION = "0.6.4"
2
+ VERSION = "0.6.5"
3
3
  end
@@ -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
 
@@ -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
@@ -21,5 +21,4 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency "activesupport", ">=3.2"
22
22
  gem.add_dependency "oj", ">=2.0"
23
23
  gem.add_development_dependency "rspec", ">= 2.12.0"
24
- gem.add_development_dependency "guard-rspec", ">=2.2.2"
25
24
  end
@@ -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
@@ -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
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: 2013-11-07 00:00:00.000000000 Z
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