nori 2.0.4 → 2.1.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/CHANGELOG.md +16 -0
- data/Gemfile +1 -3
- data/lib/nori.rb +17 -0
- data/lib/nori/version.rb +1 -1
- data/lib/nori/xml_utility_node.rb +1 -3
- data/spec/nori/api_spec.rb +25 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# 2.1.0 (2013-04-21)
|
2
|
+
|
3
|
+
* Feature: Added `Nori.hash_key` and `Nori#find` to work with Hash keys generated by Nori.
|
4
|
+
Original issue: [savonrb/savon#393](https://github.com/savonrb/savon/pull/393)
|
5
|
+
|
1
6
|
# 2.0.4 (2013-02-26)
|
2
7
|
|
3
8
|
* Fix: [#37](https://github.com/savonrb/nori/issues/37) special characters
|
@@ -40,6 +45,17 @@ Please make sure to read the updated README for how to use the new version.
|
|
40
45
|
|
41
46
|
* Fix: [#16](https://github.com/savonrb/nori/issues/16) strip XML passed to Nori.
|
42
47
|
|
48
|
+
## 1.1.5 (2013-03-03)
|
49
|
+
|
50
|
+
* Fix: [#37](https://github.com/savonrb/nori/issues/37) special characters
|
51
|
+
problem on Ruby 1.9.3-p392.
|
52
|
+
|
53
|
+
## 1.1.4 (2013-01-10)
|
54
|
+
|
55
|
+
* Fix for remote code execution bug. For more in-depth information, read about the
|
56
|
+
recent [Rails hotfix](https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/61bkgvnSGTQ).
|
57
|
+
Please make sure to upgrade now!
|
58
|
+
|
43
59
|
## 1.1.3 (2012-07-12)
|
44
60
|
|
45
61
|
* Fix: Merged [pull request 21](https://github.com/savonrb/nori/pull/21) to fix an
|
data/Gemfile
CHANGED
data/lib/nori.rb
CHANGED
@@ -4,6 +4,13 @@ require "nori/xml_utility_node"
|
|
4
4
|
|
5
5
|
class Nori
|
6
6
|
|
7
|
+
def self.hash_key(name, options = {})
|
8
|
+
name = name.tr("-", "_")
|
9
|
+
name = name.split(":").last if options[:strip_namespaces]
|
10
|
+
name = options[:convert_tags_to].call(name) if options[:convert_tags_to].respond_to? :call
|
11
|
+
name
|
12
|
+
end
|
13
|
+
|
7
14
|
PARSERS = { :rexml => "REXML", :nokogiri => "Nokogiri" }
|
8
15
|
|
9
16
|
def initialize(options = {})
|
@@ -18,6 +25,16 @@ class Nori
|
|
18
25
|
@options = defaults.merge(options)
|
19
26
|
end
|
20
27
|
|
28
|
+
def find(hash, *path)
|
29
|
+
return hash if path.empty?
|
30
|
+
|
31
|
+
key = path.shift
|
32
|
+
key = self.class.hash_key(key, @options)
|
33
|
+
|
34
|
+
return nil unless hash.include? key
|
35
|
+
find(hash[key], *path)
|
36
|
+
end
|
37
|
+
|
21
38
|
def parse(xml)
|
22
39
|
cleaned_xml = xml.strip
|
23
40
|
return {} if cleaned_xml.empty?
|
data/lib/nori/version.rb
CHANGED
@@ -90,9 +90,7 @@ class Nori
|
|
90
90
|
end.flatten]
|
91
91
|
|
92
92
|
@options = options
|
93
|
-
@name
|
94
|
-
@name = @name.split(":").last if @options[:strip_namespaces]
|
95
|
-
@name = @options[:convert_tags_to].call(@name) if @options[:convert_tags_to].respond_to? :call
|
93
|
+
@name = Nori.hash_key(name, options)
|
96
94
|
|
97
95
|
# leave the type alone if we don't know what it is
|
98
96
|
@type = self.class.available_typecasts.include?(attributes["type"]) ? attributes.delete("type") : attributes["type"]
|
data/spec/nori/api_spec.rb
CHANGED
@@ -62,6 +62,31 @@ describe Nori do
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
context '#find' do
|
66
|
+
before do
|
67
|
+
upcase = lambda { |tag| tag.upcase }
|
68
|
+
@nori = nori(:convert_tags_to => upcase)
|
69
|
+
|
70
|
+
xml = '<userResponse id="1"><accountStatus>active</accountStatus></userResponse>'
|
71
|
+
@hash = @nori.parse(xml)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns the Hash when the path is empty' do
|
75
|
+
result = @nori.find(@hash)
|
76
|
+
expect(result).to eq("USERRESPONSE" => { "ACCOUNTSTATUS" => "active", "@ID" => "1" })
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'returns the result for a single key' do
|
80
|
+
result = @nori.find(@hash, 'userResponse')
|
81
|
+
expect(result).to eq("ACCOUNTSTATUS" => "active", "@ID" => "1")
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns the result for nested keys' do
|
85
|
+
result = @nori.find(@hash, 'userResponse', 'accountStatus')
|
86
|
+
expect(result).to eq("active")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
65
90
|
context "#parse" do
|
66
91
|
it "defaults to use advanced typecasting" do
|
67
92
|
hash = nori.parse("<value>true</value>")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nori
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-04-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
segments:
|
111
111
|
- 0
|
112
|
-
hash:
|
112
|
+
hash: 2288822480346077713
|
113
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
114
|
none: false
|
115
115
|
requirements:
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash:
|
121
|
+
hash: 2288822480346077713
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project: nori
|
124
124
|
rubygems_version: 1.8.24
|