Skip to content
Merged
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions lib/fromRdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,12 @@ function _RDFToObject(o, useNativeTypes, rdfDirection, options) {
// use native types for certain xsd types
if(useNativeTypes) {
if(type === XSD_BOOLEAN) {
if(rval['@value'] === 'true') {
if(rval['@value'] === 'true' || rval['@value'] === '1') {
rval['@value'] = true;
} else if(rval['@value'] === 'false') {
} else if(rval['@value'] === 'false' || rval['@value'] === '0') {
rval['@value'] = false;
} else if(rval['@value'] === 'True' || rval['@value'] === 'False') {
rval['@type'] = type;
Copy link

@filip26 filip26 Oct 28, 2025

Choose a reason for hiding this comment

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

This should simply be an else. In other words:

  • If the value is "true" (line 353), use the native true.
  • If the value is "false" (line 355), use the native false.
  • If it cannot be coerced to native types (i.e., not true, 1, false, or 0), keep it as is, that is, set the type to boolean, but do not convert the value to native types.
} else {
  rval['@type'] = type;
}

Copy link

Choose a reason for hiding this comment

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

Thinking about it more, you should not get '1' or '0' from RDF.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking about it more, you should not get '1' or '0' from RDF.

Supporting those was part of why the newer test exists. What did you mean?

This should simply be an else.

Yes, I got confused. Made a test suite PR to help clarify and handle another similar case that this code would fail on.
w3c/json-ld-api#669

Copy link

Choose a reason for hiding this comment

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

Yes, it's confusing but please keep the test as is, see w3c/json-ld-api#669 (comment).

Your fix is almost OK, just the plain else and it should work.

}
} else if(types.isNumeric(rval['@value'])) {
if(type === XSD_INTEGER) {
Expand All @@ -364,6 +366,10 @@ function _RDFToObject(o, useNativeTypes, rdfDirection, options) {
} else if(type === XSD_DOUBLE) {
rval['@value'] = parseFloat(rval['@value']);
}
} else if(type == XSD_DOUBLE) {
// if not numeric and double, include type
// occurs for valid strings such as "+INF", "-INF", and large values
rval['@type'] = type;
}
// do not add native type
if(![XSD_BOOLEAN, XSD_INTEGER, XSD_DOUBLE, XSD_STRING].includes(type)) {
Expand Down