Skip to content

fix(opencode): handle non-object JSON in parseManagedPlist#22319

Open
shafdev wants to merge 2 commits intoanomalyco:devfrom
shafdev:fix/parse-managed-plist-non-object
Open

fix(opencode): handle non-object JSON in parseManagedPlist#22319
shafdev wants to merge 2 commits intoanomalyco:devfrom
shafdev:fix/parse-managed-plist-non-object

Conversation

@shafdev
Copy link
Copy Markdown
Contributor

@shafdev shafdev commented Apr 13, 2026

Issue for this PR

Closes #22318

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

parseManagedPlist calls Object.keys() directly on the result of JSON.parse() without checking the type first. If an MDM profile is malformed and produces null, this throws TypeError: null is not an object. Arrays and primitives also cause unexpected errors.

Added a type guard before the loop to return {} early for anything that isn't a plain object.

How did you verify your code works?

Reproduced the crash before the fix:

cd packages/opencode
bun -e "const { Config } = await import('./src/config/config'); Config.parseManagedPlist('null', 'test')"
# TypeError: null is not an object

After the fix, all non-object inputs return {} without throwing. Added 3 tests covering null, array, and number inputs — all pass.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: parseManagedPlist crashes with TypeError on non-object JSON

1 participant