Skip to content

Don't expand non-string native values to node objects. #209

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
Jan 9, 2018
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
Expand Up @@ -5,6 +5,9 @@
feature added complexity and browser issues and the use case is likely
handled by semantic versioning and using a proper dependency.

## 0.5.x
- Do not use native types to create IRIs in value expansion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to make this follow our convention. @davidlehn -- any tips/links to point out?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added similar comment here: https://github.com/digitalbazaar/jsonld.js/pull/210/files#r160245707
I'll fix it for next 0.5.x release.

## 0.5.15 - 2017-10-16

### Changed
Expand Down
11 changes: 5 additions & 6 deletions lib/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ api.expand = ({
// add value for property
// use an array except for certain keywords
const useArray =
['@index', '@id', '@type', '@value', '@language'].indexOf(
expandedProperty) === -1;
!['@index', '@id', '@type', '@value', '@language'].includes(expandedProperty);
_addValue(
rval, expandedProperty, expandedValue, {propertyIsArray: useArray});
}
Expand Down Expand Up @@ -575,11 +574,11 @@ function _expandValue({activeCtx, activeProperty, value}) {
const type = _getContextValue(activeCtx, activeProperty, '@type');

// do @id expansion (automatic for @graph)
if(type === '@id' || (expandedProperty === '@graph' && _isString(value))) {
if((type === '@id' || expandedProperty === '@graph') && _isString(value)) {
return {'@id': _expandIri(activeCtx, value, {base: true})};
}
// do @id expansion w/vocab
if(type === '@vocab') {
if(type === '@vocab' && _isString(value)) {
return {'@id': _expandIri(activeCtx, value, {vocab: true, base: true})};
}

Expand All @@ -590,7 +589,7 @@ function _expandValue({activeCtx, activeProperty, value}) {

const rval = {};

if(type !== null) {
if(type && !['@id', '@vocab'].includes(type)) {
// other type
rval['@type'] = type;
} else if(_isString(value)) {
Expand All @@ -601,7 +600,7 @@ function _expandValue({activeCtx, activeProperty, value}) {
}
}
// do conversion of values that aren't basic JSON types to strings
if(['boolean', 'number', 'string'].indexOf(typeof value) === -1) {
if(!['boolean', 'number', 'string'].includes(typeof value)) {
value = value.toString();
}
rval['@value'] = value;
Expand Down
3 changes: 1 addition & 2 deletions lib/fromRdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ function _RDFToObject(o, useNativeTypes) {
}
}
// do not add native type
if([XSD_BOOLEAN, XSD_INTEGER, XSD_DOUBLE, XSD_STRING]
.indexOf(type) === -1) {
if(![XSD_BOOLEAN, XSD_INTEGER, XSD_DOUBLE, XSD_STRING].includes(type)) {
rval['@type'] = type;
}
} else if(type !== XSD_STRING) {
Expand Down