Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dup strings in case they're frozen before force_encoding #445

Merged
merged 2 commits into from Aug 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/gems/pending/util/xml/miq_rexml.rb
Expand Up @@ -147,7 +147,7 @@ def initialize(first, second = nil, parent = nil)
@value = Text.unnormalize(second.to_s, nil)
rescue => err
if err.class == ::Encoding::CompatibilityError
second_utf8 = second.to_s.force_encoding('UTF-8').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '')
second_utf8 = second.to_s.dup.force_encoding('UTF-8').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '')
@value = Text.unnormalize(second_utf8)
else
$log.error "Encoding error: #{second_utf8}" if $log
Expand Down Expand Up @@ -228,7 +228,7 @@ def add_element(element, attrs = nil)

alias_method :add_attribute_orig, :add_attribute
def add_attribute(key, value)
value_utf8 = value.to_s.force_encoding('UTF-8').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '') unless value.nil?
value_utf8 = value.to_s.dup.force_encoding('UTF-8').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '') unless value.nil?
add_attribute_orig(key.to_s, value_utf8) unless value_utf8.nil?
end

Expand Down