diff --git a/lib/rdf/ntriples/writer.rb b/lib/rdf/ntriples/writer.rb index 5ea28f37..c155bd74 100644 --- a/lib/rdf/ntriples/writer.rb +++ b/lib/rdf/ntriples/writer.rb @@ -131,11 +131,10 @@ def self.escape_ascii(u, encoding) when (0x0C) then "\\f" when (0x0D) then "\\r" when (0x22) then "\\\"" - when (0x27) then "\\'" when (0x5C) then "\\\\" when (0x00..0x1F) then escape_utf16(u) when (0x7F) then escape_utf16(u) - when (0x00..0x7F) then u.chr + when (0x20..0x7E) then u.chr else raise ArgumentError.new("expected an ASCII character in (0x00..0x7F), but got 0x#{u.to_s(16)}") end diff --git a/spec/ntriples_spec.rb b/spec/ntriples_spec.rb index 4a359a72..1622cdf1 100644 --- a/spec/ntriples_spec.rb +++ b/spec/ntriples_spec.rb @@ -573,7 +573,7 @@ end end - context "Writing a Statements" do + context "Writing Statements" do let(:statements) {[ RDF::Statement(RDF::URI('s'), RDF::URI('p'), RDF::URI('o1')), RDF::Statement(RDF::URI('s'), RDF::URI('p'), RDF::URI('o2')) @@ -600,6 +600,10 @@ expect(writer.new.format_literal(RDF::Literal.new('Hello, world!'))).to eq '"Hello, world!"' end + it "should correctly format string literals" do + expect(writer.new.format_literal(RDF::Literal.new('Hello, world!', datatype: RDF::XSD.string))).to eq '"Hello, world!"' + end + it "should correctly format language-tagged literals" do expect(writer.new.format_literal(RDF::Literal.new('Hello, world!', language: :en))).to eq '"Hello, world!"@en' end @@ -858,7 +862,7 @@ (0x20..0x21).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr } expect(writer.escape(0x22.chr, encoding)).to eq "\\\"" (0x23..0x26).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr } - expect(writer.escape(0x27.chr, encoding)).to eq "\\'" + expect(writer.escape(0x27.chr, encoding)).to eq "'" (0x28..0x5B).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr } expect(writer.escape(0x5C.chr, encoding)).to eq "\\\\" (0x5D..0x7E).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr } @@ -920,7 +924,7 @@ (0x20..0x21).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr } expect(writer.escape(0x22.chr, encoding)).to eq "\\\"" (0x23..0x26).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr } - expect(writer.escape(0x27.chr, encoding)).to eq "\\'" + expect(writer.escape(0x27.chr, encoding)).to eq "'" (0x28..0x5B).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr } expect(writer.escape(0x5C.chr, encoding)).to eq "\\\\" (0x5D..0x7E).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr }