From f714a02d1dce024ed9cccd48d2d4d87c06c502f0 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Thu, 13 Apr 2017 23:17:40 +0200 Subject: [PATCH] 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 --- lib/json/ld/utils.ex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/json/ld/utils.ex b/lib/json/ld/utils.ex index c5d459f..6c3a449 100644 --- a/lib/json/ld/utils.ex +++ b/lib/json/ld/utils.ex @@ -42,12 +42,12 @@ 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 + _ -> nil end end