Skip to content

Fix JSON literal value version 1 check. #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# jsonld ChangeLog

### Fixed
- JSON literal value handling issues.

## 2.0.0 - 2019-12-09

### Notes
Expand Down
21 changes: 11 additions & 10 deletions lib/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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});
}
}

Expand Down