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 defp base_uri!(opts) do
base_uri = Keyword.fetch!(opts, :base_uri) 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, raise RDF.Namespace.InvalidVocabBaseURIError,
"a base_uri without a trailing '/' or '#' is invalid" "a base_uri without a trailing '/' or '#' is invalid"
else else

View file

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