Skip to content

Commit f64e5d6

Browse files
Copilotcubap
andcommitted
Add null check validation for primeID before parsing
Co-authored-by: cubap <1119165+cubap@users.noreply.github.com>
1 parent f5a77fb commit f64e5d6

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

controllers/delete.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,13 @@ async function getAllVersions(obj) {
224224
let rootObj
225225
if (primeID === "root") {
226226
rootObj = JSON.parse(JSON.stringify(obj))
227-
} else {
227+
} else if (primeID) {
228228
//Use _id for indexed query performance instead of @id
229229
const primeHexId = parseDocumentID(primeID)
230230
rootObj = await db.findOne({"$or":[{"_id": primeHexId}, {"__rerum.slug": primeHexId}]})
231+
} else {
232+
//primeID is undefined or null, cannot proceed
233+
throw new Error("Object has no valid history.prime value")
231234
}
232235
ls_versions = await db.find({ "__rerum.history.prime": rootObj['@id'] }).toArray()
233236
ls_versions.unshift(rootObj)

controllers/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,14 @@ async function getAllVersions(obj) {
202202
if (primeID === "root") {
203203
//The obj passed in is root. So it is the rootObj we need.
204204
rootObj = JSON.parse(JSON.stringify(obj))
205-
} else {
205+
} else if (primeID) {
206206
//The obj passed in knows the ID of root, grab it from Mongo
207207
//Use _id for indexed query performance instead of @id
208208
const primeHexId = parseDocumentID(primeID)
209209
rootObj = await db.findOne({"$or":[{"_id": primeHexId}, {"__rerum.slug": primeHexId}]})
210+
} else {
211+
//primeID is undefined or null, cannot proceed
212+
throw new Error("Object has no valid history.prime value")
210213
}
211214
//All the children of this object will have its @id in __rerum.history.prime
212215
ls_versions = await db.find({ "__rerum.history.prime": rootObj['@id'] }).toArray()

0 commit comments

Comments
 (0)