Skip to content

Commit 9df4cc9

Browse files
committed
Added restrictions on classes that can be parsed.
1 parent 5cc6a7e commit 9df4cc9

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

lib/xmlrpc/parser.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ def self.struct(hash)
114114
mod = Module
115115
klass.split("::").each {|const| mod = mod.const_get(const.strip)}
116116

117-
obj = mod.allocate
118-
119-
hash.delete "___class___"
120-
hash.each {|key, value|
121-
obj.instance_variable_set("@#{ key }", value) if key =~ /^([a-zA-Z_]\w*)$/
122-
}
123-
obj
117+
if mod.included_modules.include? XMLRPC::Marshallable
118+
obj = mod.allocate
119+
120+
hash.delete "___class___"
121+
hash.each {|key, value|
122+
obj.instance_variable_set("@#{ key }", value) if key =~ /^([a-zA-Z_]\w*)$/
123+
}
124+
obj
125+
end
124126
rescue
125127
hash
126128
end

test/data/marshallable.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
- true
3+
- ''

test/data/marshallable.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" ?><methodResponse><params><param><value><struct><member><name>___class___</name><value><string>Gem::Requirement</string></value></member></struct></value></param></params></methodResponse>

test/test_parser.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ def setup
2525
@datetime_xml = File.read(datafile('datetime_iso8601.xml'))
2626
@datetime_expected = XMLRPC::DateTime.new(2004, 11, 5, 1, 15, 23)
2727

28+
@marshallable_xml, @marshallable_expected = load_data('marshallable')
29+
2830
@fault_doc = File.read(datafile('fault.xml'))
31+
@marshallable = File.read(datafile('marshallable.xml'))
2932
end
3033

3134
# test parseMethodResponse --------------------------------------------------
@@ -50,6 +53,11 @@ def test_dateTime
5053
assert_equal(@datetime_expected, @p.parseMethodResponse(@datetime_xml)[1])
5154
end
5255

56+
def test_marshallable
57+
assert_equal(@marshallable_expected, @p.parseMethodResponse(@marshallable))
58+
end
59+
60+
5361
# test parseMethodCall ------------------------------------------------------
5462

5563
def test_parseMethodCall

0 commit comments

Comments
 (0)