json_ld: fix bug in compact_iri_parts

binary_part can't handle the case where the length of the binary is shorter than the requested part
This commit is contained in:
Marcel Otto 2017-04-13 23:17:40 +02:00
parent 96874c3e3c
commit f714a02d1d

View file

@ -42,10 +42,10 @@ defmodule JSON.LD.Utils do
do: not (JSON.LD.keyword?(value) or absolute_iri?(value) or blank_node_id?(value))
def compact_iri_parts(compact_iri, exclude_bnode \\ true) do
with [prefix, suffix] when not(binary_part(suffix, 0, 2) == "//") and
not(exclude_bnode and prefix == "_") <-
String.split(compact_iri, ":", parts: 2) do
[prefix, suffix]
with [prefix, suffix] <- String.split(compact_iri, ":", parts: 2) do
if not(String.starts_with?(suffix, "//")) and
not(exclude_bnode and prefix == "_"),
do: [prefix, suffix]
else
_ -> nil
end