Skip to content

Commit e552868

Browse files
committed
OneLogin::RubySaml::Utils.element_text should normalize text before returning it.
Fixes #445.
1 parent 0a7d012 commit e552868

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/onelogin/ruby-saml/utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def self.original_uri_match?(destination_url, settings_url)
286286
# that there all children other than text nodes can be ignored (e.g. comments). If nil is
287287
# passed, nil will be returned.
288288
def self.element_text(element)
289-
element.texts.join if element
289+
element.texts.map(&:value).join if element
290290
end
291291
end
292292
end

test/utils_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,22 @@ class UtilsTest < Minitest::Test
213213
assert !OneLogin::RubySaml::Utils.uri_match?(destination, settings)
214214
end
215215
end
216+
217+
describe 'element_text' do
218+
it 'returns the element text' do
219+
element = REXML::Document.new('<element>element text</element>').elements.first
220+
assert_equal 'element text', OneLogin::RubySaml::Utils.element_text(element)
221+
end
222+
223+
it 'returns all segments of the element text' do
224+
element = REXML::Document.new('<element>element <!-- comment -->text</element>').elements.first
225+
assert_equal 'element text', OneLogin::RubySaml::Utils.element_text(element)
226+
end
227+
228+
it 'returns normalized element text' do
229+
element = REXML::Document.new('<element>element &amp; text</element>').elements.first
230+
assert_equal 'element & text', OneLogin::RubySaml::Utils.element_text(element)
231+
end
232+
end
216233
end
217234
end

0 commit comments

Comments
 (0)