Change RDF.IRI.absolute/2 to return nil if the base is not absolute
This commit is contained in:
parent
1c7cad39be
commit
6bafb41cf9
3 changed files with 14 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue