diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cef6bf..c42bfc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ This project adheres to [Semantic Versioning](http://semver.org/) and - Elixir 1.4 is no longer supported - `RDF.String.new/2` and `RDF.String.new!/2` produce a `rdf:langString` when given a language tag +- `RDF.IRI.absolute/2` returns `nil` if the given base is not absolute, instead + of failing with a `FunctionClauseError` ### Fixed diff --git a/lib/rdf/iri.ex b/lib/rdf/iri.ex index 0c37a00..3fb3d34 100644 --- a/lib/rdf/iri.ex +++ b/lib/rdf/iri.ex @@ -126,12 +126,14 @@ defmodule RDF.IRI do Characters additionally allowed in IRI references are treated in the same way that unreserved characters are treated in URI references, per [section 6.5 of RFC3987](http://tools.ietf.org/html/rfc3987#section-6.5) + + If the given is not an absolute IRI `nil` is returned. """ def absolute(iri, base) do - if absolute?(iri) do - new(iri) - else - merge(base, iri) + cond do + absolute?(iri) -> new(iri) + not absolute?(base) -> nil + true -> merge(base, iri) end end diff --git a/test/unit/iri_test.exs b/test/unit/iri_test.exs index 86881ea..808e343 100644 --- a/test/unit/iri_test.exs +++ b/test/unit/iri_test.exs @@ -223,6 +223,12 @@ defmodule RDF.IRITest do IRI.merge(base_iri, relative_iri) end end + + test "with a relative iri without an absolute base iri" do + for relative_iri <- relative_iris(), base_iri <- [nil, "foo"] do + assert IRI.absolute(relative_iri, base_iri) == nil + end + end end