From 3201e8c40b702cfd27535bc05cad87af88be3622 Mon Sep 17 00:00:00 2001 From: Adam Brodziak Date: Fri, 25 Aug 2017 22:30:07 +0200 Subject: [PATCH] Fix compacting empty list mapped @type: @id It sets default common type to `@id` for an empty list. Extracted from existing algorithm where `@id` was a default type if list item was not a value (empty is not a value). The test case has been marked for 1.1 version of the spec, but has been considered as an errata to 1.0 spec as well. See comment: https://github.com/json-ld/json-ld.org/pull/510#issuecomment-312456440 This fixes #189 issue. --- js/jsonld.js | 2 +- tests/test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/jsonld.js b/js/jsonld.js index f2acbeb0..a392f471 100644 --- a/js/jsonld.js +++ b/js/jsonld.js @@ -5531,7 +5531,7 @@ function _compactIri(activeCtx, iri, value, relativeTo, reverse) { } var list = value['@list']; var commonLanguage = (list.length === 0) ? defaultLanguage : null; - var commonType = null; + var commonType = (list.length === 0) ? '@id' : null; for(var i = 0; i < list.length; ++i) { var item = list[i]; var itemLanguage = '@none'; diff --git a/tests/test.js b/tests/test.js index b371cc6c..da8d7a02 100644 --- a/tests/test.js +++ b/tests/test.js @@ -96,7 +96,7 @@ var ROOT_MANIFEST_DIR = resolvePath( var TEST_TYPES = { 'jld:CompactTest': { skip: { - regex: [/#t0073/, /#t0074/], + regex: [/#t0073/], specVersion: ['json-ld-1.1'] }, fn: 'compact',