Skip to content

Commit a57aa3f

Browse files
committed
Prevent breaks when parsing recordings with invalid times
It would break parsing a getRecordings if one of them had an empty startTime or endTime.
1 parent e143ec8 commit a57aa3f

2 files changed

Lines changed: 39 additions & 8 deletions

File tree

lib/bigbluebutton_formatter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def to_datetime(key)
4949
if value.is_a?(Numeric)
5050
result = value == 0 ? nil : DateTime.parse(Time.at(value/1000.0).to_s)
5151
else
52-
if value.downcase == "null"
52+
if (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
53+
result = nil
54+
elsif value.is_a?(String) && (value.empty? || value.downcase == 'null')
5355
result = nil
5456
else
5557
# note: just in case the value comes as a string in the format: "Thu Sep 01 17:51:42 UTC 2011"

spec/bigbluebutton_formatter_spec.rb

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,43 @@
100100
it { hash[:param7].should == nil }
101101
it { hash[:param8].should == nil }
102102

103-
context "returns nil if the param doesn't exists" do
104-
subject { BigBlueButton::BigBlueButtonFormatter.new({ :param => 1}) }
105-
it { subject.to_datetime(:inexistent).should == nil }
106-
end
103+
context "returns nil if" do
104+
context "the param doesn't exists" do
105+
subject { BigBlueButton::BigBlueButtonFormatter.new({ :param => 1}) }
106+
it { subject.to_datetime(:inexistent).should == nil }
107+
end
107108

108-
context "returns nil if the hash is nil" do
109-
subject { BigBlueButton::BigBlueButtonFormatter.new(nil) }
110-
it { subject.to_datetime(:inexistent).should == nil }
109+
context "the hash is nil" do
110+
subject { BigBlueButton::BigBlueButtonFormatter.new(nil) }
111+
it { subject.to_datetime(:inexistent).should == nil }
112+
end
113+
114+
context "the value is an empty string" do
115+
subject { BigBlueButton::BigBlueButtonFormatter.new({ param1: '' }) }
116+
it { subject.to_datetime(:param1).should == nil }
117+
end
118+
119+
context "the value is nil" do
120+
subject { BigBlueButton::BigBlueButtonFormatter.new({ param1: nil }) }
121+
it { subject.to_datetime(:param1).should == nil }
122+
end
123+
124+
context "the value is an empty hash" do
125+
subject { BigBlueButton::BigBlueButtonFormatter.new({ param1: {} }) }
126+
it { subject.to_datetime(:param1).should == nil }
127+
end
128+
129+
context "the value is an empty array" do
130+
subject { BigBlueButton::BigBlueButtonFormatter.new({ param1: [] }) }
131+
it { subject.to_datetime(:param1).should == nil }
132+
end
133+
134+
['null', 'NULL'].each do |v|
135+
context "the value is '#{v}'" do
136+
subject { BigBlueButton::BigBlueButtonFormatter.new({ param1: v }) }
137+
it { subject.to_datetime(:param1).should == nil }
138+
end
139+
end
111140
end
112141
end
113142

0 commit comments

Comments
 (0)