Skip to content

Commit b3475c9

Browse files
committed
Handle non-string id blank node edge case.
In the case where an `@id` is not a string, consider an object a blank node. This is needed to handle a crashing error where the code assumes ids are valid strings. The error could occur with direct invalid input, or in the edge case where non-normative invalid intermediate expanded JSON-LD is generated.
1 parent 07d41d4 commit b3475c9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/graphTypes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ api.isSimpleGraph = v => {
106106
api.isBlankNode = v => {
107107
// Note: A value is a blank node if all of these hold true:
108108
// 1. It is an Object.
109-
// 2. If it has an @id key its value begins with '_:'.
109+
// 2. If it has an @id key that is not a string OR begins with '_:'.
110110
// 3. It has no keys OR is not a @value, @set, or @list.
111111
if(types.isObject(v)) {
112112
if('@id' in v) {
113-
return (v['@id'].indexOf('_:') === 0);
113+
const id = v['@id'];
114+
return !types.isString(id) || id.indexOf('_:') === 0;
114115
}
115116
return (Object.keys(v).length === 0 ||
116117
!(('@value' in v) || ('@set' in v) || ('@list' in v)));

0 commit comments

Comments
 (0)