Skip to content

Commit ac80b2f

Browse files
committed
Update N-Triples/Quads ASCII escapes when writing literals based on proposed RDF 1.2 behavior.
1 parent 1cb1562 commit ac80b2f

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

lib/rdf/ntriples/writer.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,10 @@ def self.escape_ascii(u, encoding)
131131
when (0x0C) then "\\f"
132132
when (0x0D) then "\\r"
133133
when (0x22) then "\\\""
134-
when (0x27) then "\\'"
135134
when (0x5C) then "\\\\"
136135
when (0x00..0x1F) then escape_utf16(u)
137136
when (0x7F) then escape_utf16(u)
138-
when (0x00..0x7F) then u.chr
137+
when (0x20..0x7E) then u.chr
139138
else
140139
raise ArgumentError.new("expected an ASCII character in (0x00..0x7F), but got 0x#{u.to_s(16)}")
141140
end

spec/ntriples_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@
573573
end
574574
end
575575

576-
context "Writing a Statements" do
576+
context "Writing Statements" do
577577
let(:statements) {[
578578
RDF::Statement(RDF::URI('s'), RDF::URI('p'), RDF::URI('o1')),
579579
RDF::Statement(RDF::URI('s'), RDF::URI('p'), RDF::URI('o2'))
@@ -600,6 +600,10 @@
600600
expect(writer.new.format_literal(RDF::Literal.new('Hello, world!'))).to eq '"Hello, world!"'
601601
end
602602

603+
it "should correctly format string literals" do
604+
expect(writer.new.format_literal(RDF::Literal.new('Hello, world!', datatype: RDF::XSD.string))).to eq '"Hello, world!"'
605+
end
606+
603607
it "should correctly format language-tagged literals" do
604608
expect(writer.new.format_literal(RDF::Literal.new('Hello, world!', language: :en))).to eq '"Hello, world!"@en'
605609
end
@@ -858,7 +862,7 @@
858862
(0x20..0x21).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr }
859863
expect(writer.escape(0x22.chr, encoding)).to eq "\\\""
860864
(0x23..0x26).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr }
861-
expect(writer.escape(0x27.chr, encoding)).to eq "\\'"
865+
expect(writer.escape(0x27.chr, encoding)).to eq "'"
862866
(0x28..0x5B).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr }
863867
expect(writer.escape(0x5C.chr, encoding)).to eq "\\\\"
864868
(0x5D..0x7E).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr }
@@ -920,7 +924,7 @@
920924
(0x20..0x21).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr }
921925
expect(writer.escape(0x22.chr, encoding)).to eq "\\\""
922926
(0x23..0x26).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr }
923-
expect(writer.escape(0x27.chr, encoding)).to eq "\\'"
927+
expect(writer.escape(0x27.chr, encoding)).to eq "'"
924928
(0x28..0x5B).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr }
925929
expect(writer.escape(0x5C.chr, encoding)).to eq "\\\\"
926930
(0x5D..0x7E).each { |u| expect(writer.escape(u.chr, encoding)).to eq u.chr }

0 commit comments

Comments
 (0)