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

Escape all instances of " in """ delimited literals #17

Merged
merged 1 commit into from Feb 8, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rdf/turtle/writer.rb
Expand Up @@ -447,7 +447,8 @@ def reset
# @return [String]
def quoted(string)
if string.to_s.match(/[\t\n\r]/)
string = string.gsub('\\', '\\\\\\\\').gsub('"""', '\\"""')
string = string.gsub('\\', '\\\\\\\\').gsub('"', '\\"')

%("""#{string}""")
else
"\"#{escaped(string)}\""
Expand Down
33 changes: 24 additions & 9 deletions spec/writer_spec.rb
Expand Up @@ -147,7 +147,7 @@
end
end
end

describe "lists" do
{
"bare list": {
Expand Down Expand Up @@ -301,7 +301,7 @@
describe "literals" do
describe "plain" do
{
"embedded \"\"\"": {
"\"\"\" delimited": {
input: %(<http://a> <http:/b> """testing string parsing in Turtle.\n""" .),
regexp: [/testing string parsing in Turtle.\n/]
},
Expand All @@ -318,20 +318,35 @@
regexp: [/string with \\\\ escaped quote mark/],
prefixes: {nil => ""}
},
"embedded \"\"\" multi-line": {
input: %(:a :b """string with \\""" escaped triple-quote marks\n""" .),
regexp: [/string with \\"\\"\\" escaped triple-quote marks/],
prefixes: {nil => ""}
},
"embedded \"\"\"\"\" multi-line": {
input: %(:a :b """string with many \\"""\\"" escaped quote marks\n""" .),
regexp: [/string with many \\"\\"\\"\\"\\" escaped quote marks/],
prefixes: {nil => ""}
},
"ending \" multi-line": {
input: %(:a :b """multi-line \nstring with ending \\"quote marks\\\"""" .),
regexp: [/multi-line \nstring with ending \\"quote marks\\"/],
prefixes: {nil => ""}
},
}.each do |name, params|
it name do
serialize(params[:input], params[:regexp], params)
end
end
end

describe "with language" do
it "specifies language for literal with language" do
ttl = %q(<http://a> <http:/b> "string"@en .)
serialize(ttl, [%r("string"@en)])
end
end

describe "xsd:anyURI" do
it "uses xsd namespace for datatype" do
ttl = %q(@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . <http://a> <http:/b> "http://foo/"^^xsd:anyURI .)
Expand All @@ -341,7 +356,7 @@
])
end
end

describe "xsd:boolean" do
[
[%q("true"^^xsd:boolean), /true ./],
Expand Down Expand Up @@ -397,7 +412,7 @@
end
end
end

describe "xsd:integer" do
[
[%q("1"^^xsd:integer), /1 ./],
Expand Down Expand Up @@ -520,7 +535,7 @@
end
end
end

describe "xsd:double" do
[
[%q("1.0e1"^^xsd:double), /1.0e1 ./],
Expand Down Expand Up @@ -639,7 +654,7 @@ def serialize(ntstr, regexps = [], base_uri: nil, **options)
logger.info "match: #{re.inspect}"
expect(result).to match_re(re, about: base_uri, logger: logger, input: ntstr), logger.to_s
end

result
end
end
end