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

Use encode! rather than encode to modify string in place #715

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/marc_collection_document_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def start_element(name, attrs = [])

# Write any text that can be found in an open tag
def characters(string)
@io.write string.encode(xml: :text)
@io.write string.encode!(xml: :text)
end

# Write the closing tag for an element
Expand Down
4 changes: 3 additions & 1 deletion spec/models/marc_collection_document_callbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

describe '#characters' do
it "escapes special XML characters" do
document_callbacks.characters('Vols. for 1972-<1982> called also vyp. 1-<8/2>.')
# Nokogiri's SAX parser gives unfrozen strings to this callback, so we use the +
# in this test to make sure the string we pass is similarly unfrozen
document_callbacks.characters(+'Vols. for 1972-<1982> called also vyp. 1-<8/2>.')
expect(io.string).to eq('Vols. for 1972-&lt;1982&gt; called also vyp. 1-&lt;8/2&gt;.')
end
end
Expand Down
Loading