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

Force RDF data to be UTF-8 #286

Merged
merged 1 commit into from
Dec 17, 2013
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 lib/active_fedora/rdf_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def deserialize(data = nil)
return repository if new? and data.nil?

data ||= datastream_content

data.force_encoding('utf-8')
RDF::Reader.for(serialization_format).new(data) do |reader|
reader.each_statement do |statement|
repository << statement
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/rdf_datastream_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
require 'spec_helper'

describe ActiveFedora::RDFDatastream do
Expand Down Expand Up @@ -53,4 +54,15 @@ class MyObj < ActiveFedora::Base
MyDatastream.fields.should == [:title, :description]
end
end

describe "deserialize" do
it "should be able to handle non-utf-8 characters" do
# see https://github.com/ruby-rdf/rdf/issues/142
ds = ActiveFedora::NtriplesRDFDatastream.new
data = "<info:fedora/scholarsphere:qv33rx50r> <http://purl.org/dc/terms/description> \"\\n\xE2\x80\x99 \" .\n".force_encoding('ASCII-8BIT')

result = ds.deserialize(data)
result.dump(:ntriples).should == "<info:fedora/scholarsphere:qv33rx50r> <http://purl.org/dc/terms/description> \"\\n’ \" .\n"
end
end
end