core: fix pending base_uri validation on vocabulary namespaces

This commit is contained in:
Marcel Otto 2017-05-21 23:28:34 +02:00
parent e01d641290
commit ef5b5985dd
2 changed files with 6 additions and 8 deletions

View file

@ -111,7 +111,7 @@ defmodule RDF.Vocabulary.Namespace do
defp base_uri!(opts) do
base_uri = Keyword.fetch!(opts, :base_uri)
unless String.ends_with?(base_uri, ["/", "#"]) do
unless is_binary(base_uri) and String.ends_with?(base_uri, ["/", "#"]) do
raise RDF.Namespace.InvalidVocabBaseURIError,
"a base_uri without a trailing '/' or '#' is invalid"
else

View file

@ -16,7 +16,6 @@ defmodule RDF.Vocabulary.NamespaceTest do
defvocab Example2,
base_uri: "http://example.com/example2/",
file: "test/data/vocab_ns_example2.nt"
# file: "vocab_ns_example2.nt"
defvocab Example3,
base_uri: "http://example.com/example3#",
@ -30,7 +29,7 @@ defmodule RDF.Vocabulary.NamespaceTest do
describe "defvocab" do
test "fails without a base_uri" do
test "without a base_uri, an error is raised" do
assert_raise KeyError, fn ->
defmodule BadNS1 do
use RDF.Vocabulary.Namespace
@ -40,7 +39,7 @@ defmodule RDF.Vocabulary.NamespaceTest do
end
end
test "fails, when the base_uri doesn't end with '/' or '#'" do
test "when the base_uri doesn't end with '/' or '#', an error is raised" do
assert_raise RDF.Namespace.InvalidVocabBaseURIError, fn ->
defmodule BadNS2 do
use RDF.Vocabulary.Namespace
@ -52,14 +51,13 @@ defmodule RDF.Vocabulary.NamespaceTest do
end
end
@tag skip: "TODO: implement proper URI validation"
test "fails, when the base_uri isn't a valid URI according to RFC 3986" do
test "when the base_uri isn't a valid URI, an error is raised" do
assert_raise RDF.Namespace.InvalidVocabBaseURIError, fn ->
defmodule BadNS3 do
use RDF.Vocabulary.Namespace
defvocab Example,
base_uri: "foo/",
base_uri: "invalid",
terms: []
end
end
@ -74,7 +72,7 @@ defmodule RDF.Vocabulary.NamespaceTest do
end
end
test "fails, when the given file not found" do
test "when the given file not found, an error is raised" do
assert_raise File.Error, fn ->
defmodule BadNS5 do
use RDF.Vocabulary.Namespace