Add missing escaping of language-tagged literals in Turtle encoder
This commit is contained in:
parent
967f81ad5a
commit
3480c254c3
3 changed files with 18 additions and 1 deletions
|
@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
||||||
|
|
||||||
- the Turtle encoder was encoding IRIs as prefixed names even when they were
|
- the Turtle encoder was encoding IRIs as prefixed names even when they were
|
||||||
resulting in non-conform prefixed names
|
resulting in non-conform prefixed names
|
||||||
|
- the Turtle encoder didn't properly escape special characters in language-tagged
|
||||||
|
literals
|
||||||
- the `Inspect` protocol implementation for `RDF.Diff` was causing an error when
|
- the `Inspect` protocol implementation for `RDF.Diff` was causing an error when
|
||||||
both graphs had prefixes defined
|
both graphs had prefixes defined
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,7 @@ defmodule RDF.Turtle.Encoder do
|
||||||
do: to_string(bnode)
|
do: to_string(bnode)
|
||||||
|
|
||||||
defp term(%Literal{literal: %LangString{} = lang_string}, _, _, _) do
|
defp term(%Literal{literal: %LangString{} = lang_string}, _, _, _) do
|
||||||
~s["#{lang_string.value}"@#{lang_string.language}]
|
quoted(lang_string.value) <> "@" <> lang_string.language
|
||||||
end
|
end
|
||||||
|
|
||||||
defp term(%Literal{literal: %XSD.String{}} = literal, _, _, _) do
|
defp term(%Literal{literal: %XSD.String{}} = literal, _, _, _) do
|
||||||
|
|
|
@ -738,6 +738,21 @@ defmodule RDF.Turtle.EncoderTest do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "language-tagged literals with newlines embedded are encoded with long quotes" do
|
||||||
|
Turtle.read_string!(~s[<http://a> <http:/b> """testing string parsing in Turtle.
|
||||||
|
"""@en .])
|
||||||
|
|> assert_serialization(matches: [~s["""testing string parsing in Turtle.\n]])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "language-tagged literals escaping" do
|
||||||
|
Turtle.read_string!(~s[<http://a> <http:/b> """string with " escaped quote marks"""@en .])
|
||||||
|
|> assert_serialization(
|
||||||
|
matches: [
|
||||||
|
~r[string with \\" escaped quote mark]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
test "language tagged literals specifies language for literal with language" do
|
test "language tagged literals specifies language for literal with language" do
|
||||||
Turtle.read_string!(~s[<http://a> <http:/b> "string"@en .])
|
Turtle.read_string!(~s[<http://a> <http:/b> "string"@en .])
|
||||||
|> assert_serialization(matches: [~r["string"@en]])
|
|> assert_serialization(matches: [~r["string"@en]])
|
||||||
|
|
Loading…
Reference in a new issue