mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-29 01:41:22 +00:00
fix(tweet-preview): reject array inputs in parseTweetData
The previous guard accepted any non-null `typeof === "object"`, which means
`JSON.parse("[]")` or `JSON.parse("[1,2,3]")` slipped through and reached
`enrichTweet` — exactly the class of crash the helper was added to prevent.
Add an `Array.isArray` check so only plain objects are passed downstream.
This commit is contained in:
parent
e5ead50a3d
commit
0944e5fb33
1 changed files with 3 additions and 1 deletions
|
|
@ -122,7 +122,9 @@ function parseTweetData(data: Tweet | string): Tweet | null {
|
|||
if (typeof data !== "string") return data
|
||||
try {
|
||||
const parsed = JSON.parse(data)
|
||||
return parsed && typeof parsed === "object" ? (parsed as Tweet) : null
|
||||
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
||||
? (parsed as Tweet)
|
||||
: null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue