From ef5b5985dd207f791218ab8c7306c4d3ca64911a Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Sun, 21 May 2017 23:28:34 +0200 Subject: [PATCH] core: fix pending base_uri validation on vocabulary namespaces --- lib/rdf/vocabulary_namespace.ex | 2 +- test/unit/vocabulary_namespace_test.exs | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/rdf/vocabulary_namespace.ex b/lib/rdf/vocabulary_namespace.ex index 23b6067..9b8f707 100644 --- a/lib/rdf/vocabulary_namespace.ex +++ b/lib/rdf/vocabulary_namespace.ex @@ -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 diff --git a/test/unit/vocabulary_namespace_test.exs b/test/unit/vocabulary_namespace_test.exs index 1ee4d24..bdd0467 100644 --- a/test/unit/vocabulary_namespace_test.exs +++ b/test/unit/vocabulary_namespace_test.exs @@ -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