Skip to content

Commit 46edfba

Browse files
committed
Make it compatible with old versions of Ruby
1 parent b4cf36d commit 46edfba

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/onelogin/ruby-saml/attributes.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ def ==(other)
124124
def fetch(name)
125125
attributes.each_key do |attribute_key|
126126
if name.is_a?(Regexp)
127-
return self[attribute_key] if name.match?(attribute_key)
127+
if name.method_exists? :match?
128+
return self[attribute_key] if name.match?(attribute_key)
129+
else
130+
return self[attribute_key] if name.match(attribute_key)
131+
end
128132
elsif canonize_name(name) == canonize_name(attribute_key)
129133
return self[attribute_key]
130134
end

test/attributes_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class AttributesTest < Minitest::Test
2222

2323
it 'fetches regexp attribute' do
2424
assert_equal('Tom', attributes.fetch(/givenname/))
25+
assert_equal('Tom', attributes.fetch(/gi(.*)/))
26+
assert_nil(attributes.fetch(/^z.*/))
2527
assert_equal('Hanks', attributes.fetch(/surname/))
2628
end
2729
end

0 commit comments

Comments
 (0)