diff --git a/CHANGELOG.md b/CHANGELOG.md index a5b1bf60..8583b035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # jsonld ChangeLog +### Fixed +- JSON literal value handling issues. + ## 2.0.0 - 2019-12-09 ### Notes diff --git a/lib/expand.js b/lib/expand.js index e7bfae06..c8e985b3 100644 --- a/lib/expand.js +++ b/lib/expand.js @@ -406,6 +406,7 @@ async function _expandObject({ }) { const keys = Object.keys(element).sort(); const nests = []; + let unexpandedValue; for(const key of keys) { let value = element[key]; let expandedValue; @@ -513,6 +514,9 @@ async function _expandObject({ } if(expandedProperty === '@value') { + // capture value for later + // "colliding keywords" check prevents this from being set twice + unexpandedValue = value; _addValue( expandedParent, '@value', value, {propertyIsArray: options.isFrame}); continue; @@ -758,28 +762,25 @@ async function _expandObject({ } // add value for property - // use an array except for certain keywords - const useArray = - !['@index', '@id', '@type', '@value', '@language'] - .includes(expandedProperty); + // special keywords handled above _addValue(expandedParent, expandedProperty, expandedValue, { - propertyIsArray: useArray + propertyIsArray: true }); } // @value must not be an object or an array (unless framing) or if @type is // @json - if('@value' in element) { - const value = element['@value']; - if(element['@type'] === '@json' && _processingMode(activeCtx, 1.1)) { + if('@value' in expandedParent) { + if(expandedParent['@type'] === '@json' && _processingMode(activeCtx, 1.1)) { // allow any value, to be verified when the object is fully expanded and // the @type is @json. - } else if((_isObject(value) || _isArray(value)) && !options.isFrame) { + } else if((_isObject(unexpandedValue) || _isArray(unexpandedValue)) && + !options.isFrame) { throw new JsonLdError( 'Invalid JSON-LD syntax; "@value" value must not be an ' + 'object or an array.', 'jsonld.SyntaxError', - {code: 'invalid value object value', value}); + {code: 'invalid value object value', value: unexpandedValue}); } }