Skip to content

Commit 8d39707

Browse files
author
James Harris
committed
chore: guard against arrays
1 parent 3ae546f commit 8d39707

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/kitsu-core/src/deattribute/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
export function deattribute (data) {
3030
if (typeof data === 'object' && data !== null) {
3131
if (Array.isArray(data)) data.map(el => deattribute(el))
32-
else if (typeof data.attributes === 'object' && data.attributes !== null) {
32+
else if (typeof data.attributes === 'object' && !Array.isArray(data.attributes) && data.attributes !== null) {
3333
for (const key of Object.keys(data.attributes)) {
3434
// Hoist everything but attributes to parent to avoid issues with deleting
3535
// as can't delete data.attributes[key] as it will belete data[key] too

packages/kitsu-core/src/linkRelationships/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function linkRelationships (data, included = [], previouslyLinked = {}) {
120120
}
121121
}
122122

123-
if (Object.keys(relationships || []).length === 0 && typeof relationships === 'object' && relationships !== null) {
123+
if (Object.keys(relationships || []).length === 0 && typeof relationships === 'object' && !Array.isArray(relationships) && relationships !== null) {
124124
delete data.relationships
125125
}
126126

packages/kitsu-core/src/serialise/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function serialiseRelation (node, nodeType, key, data) {
106106
function serialiseAttr (node, key, data) {
107107
if (!data.attributes) data.attributes = {}
108108
if (key === 'links' && (typeof node.self === 'string' || typeof node.related === 'string')) data.links = node
109-
else if (key === 'meta' && typeof node === 'object' && node !== null) data.meta = node
109+
else if (key === 'meta' && typeof node === 'object' && !Array.isArray(node) && node !== null) data.meta = node
110110
else data.attributes[key] = node
111111
return data
112112
}
@@ -170,7 +170,7 @@ function serialiseRootObject (type, payload, method, options) {
170170
const node = payload[key]
171171
const nodeType = options.pluralTypes(options.camelCaseTypes(key))
172172
// 1. Skip null nodes, 2. Only grab objects, 3. Filter to only serialise relationable objects
173-
if (typeof node === 'object' && node !== null && hasID(node)) {
173+
if (typeof node === 'object' && !Array.isArray(node) && node !== null && hasID(node)) {
174174
data = serialiseRelation(node, nodeType, key, data)
175175
// 1. Don't place id/key inside attributes object
176176
} else if (key !== 'id' && key !== 'type') {

0 commit comments

Comments
 (0)