Skip to content

Commit 49529a3

Browse files
authored
Merge pull request #111 from mvidner/doubly-nested-variant
Fix marshalling Data::Variant, don't nest it too much.
2 parents 45414d7 + 4ea48a3 commit 49529a3

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
Bug fixes:
6+
* Properties containing Variants would return them doubly wrapped.
7+
58
## Ruby D-Bus 0.18.0.beta4 - 2022-04-21
69

710
Bug fixes:

lib/dbus/marshall.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,11 @@ def append(type, val)
282282

283283
def append_variant(val)
284284
vartype = nil
285-
if val.is_a?(DBus::Data::Base)
286-
vartype = val.type # FIXME: box or unbox another variant?
285+
if val.is_a?(DBus::Data::Variant)
286+
vartype = val.member_type
287+
vardata = val.value
288+
elsif val.is_a?(DBus::Data::Base)
289+
vartype = val.type
287290
vardata = val.value
288291
elsif val.is_a?(Array) && val.size == 2
289292
case val[0]

spec/property_spec.rb

+18-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
end
164164
end
165165

166-
context "an dict-typed property" do
166+
context "a dict-typed property" do
167167
it "gets read as a hash" do
168168
val = @iface["MyDict"]
169169
expect(val).to eq({
@@ -172,6 +172,23 @@
172172
"three" => [3, 3, 3]
173173
})
174174
end
175+
176+
it "Get returns the correctly typed value (check with dbus-send)" do
177+
cmd = "dbus-send --print-reply " \
178+
"--dest=org.ruby.service " \
179+
"/org/ruby/MyInstance " \
180+
"org.freedesktop.DBus.Properties.Get " \
181+
"string:org.ruby.SampleInterface " \
182+
"string:MyDict"
183+
reply = `#{cmd}`
184+
# a bug about variant nesting lead to a "variant variant int32 1" value
185+
match_rx = /variant \s+ array \s \[ \s+
186+
dict \s entry\( \s+
187+
string \s "one" \s+
188+
variant \s+ int32 \s 1 \s+
189+
\)/x
190+
expect(reply).to match(match_rx)
191+
end
175192
end
176193

177194
context "a variant-typed property" do

0 commit comments

Comments
 (0)