Skip to content

Commit

Permalink
Fix decoding of entities in XML
Browse files Browse the repository at this point in the history
  • Loading branch information
komuta committed Jun 12, 2017
1 parent 5034448 commit 51e609a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def windows_cleanpath(path)
end

def new_value?(document, xpath, value_to_check)
XPath.first(document, xpath).to_s != value_to_check.to_s
old_value = XPath.first(document, xpath)
return old_value.value != value_to_check.to_s unless old_value.nil?
'' != value_to_check.to_s
end

def new_or_empty_value?(document, xpath, value_to_check)
Expand Down
44 changes: 44 additions & 0 deletions spec/unit/libraries/helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Windows
module Helper
end
end

require_relative '../../../libraries/helper'
require 'rexml/document'

class Test
include Opscode::IIS::Helper
end

describe Opscode::IIS::Helper do
let(:doc) do
REXML::Document.new(xml)
end

shared_examples 'unchanged value' do
it 'should return false' do
test = Test.new
expect(test.new_value?(doc.root, '@value', new_value)).to be_falsy
end
end

describe '#new_value?' do
context 'when attribute is nil' do
let(:xml) { '<test/>' }
let(:new_value) { nil }
it_should_behave_like 'unchanged value'
end

context 'when attribut is "t&st"' do
let(:xml) { '<test value="t&amp;st"/>' }
let(:new_value) { 't&st' }
it_should_behave_like 'unchanged value'
end

context 'when attribut is ""' do
let(:xml) { '<test value=""/>' }
let(:new_value) { '' }
it_should_behave_like 'unchanged value'
end
end
end

0 comments on commit 51e609a

Please sign in to comment.