diff --git a/app/models/marc_collection_document_callbacks.rb b/app/models/marc_collection_document_callbacks.rb index 1ba03f51..9bcaa0e8 100644 --- a/app/models/marc_collection_document_callbacks.rb +++ b/app/models/marc_collection_document_callbacks.rb @@ -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 diff --git a/spec/models/marc_collection_document_callbacks_spec.rb b/spec/models/marc_collection_document_callbacks_spec.rb index f1cb4481..cae851ad 100644 --- a/spec/models/marc_collection_document_callbacks_spec.rb +++ b/spec/models/marc_collection_document_callbacks_spec.rb @@ -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-<1982> called also vyp. 1-<8/2>.') end end