Repository navigation
fix: keep Preferences from crashing the app or changing the types of stored values - #21
Merged
Merged
Conversation
added 5 commits
October 13, 2026 22:28
NSNumber casts to Bool whenever it holds 0 or 1, so a number read from UserDefaults or a property list became a Boolean. Preferences showed a nested 1 as true and saved it back as a Bool on the next edit.
preferences.set converted an Int with Int(_:), which traps outside its range, and passed null to UserDefaults, which raises an exception for a value that is not a property list. Either one terminated the app being debugged. Both are now refused as invalid input.
Saving an Array or Dictionary rewrote every row from its text, so a stored string such as "1" or "true" came back as a number or a Bool after any edit. A container holding a Date or Data is described rather than encoded as JSON, and the panel opened it as an empty editor whose Save replaced the stored value. An emptied number field saved 0. Rows now round-trip to the value they showed, a container that cannot be read is shown read-only, and an empty or unsafe number is refused.
The detail of a key was written to the pane whenever it came back. Requests overlap, so the answer for a key already left could arrive last and show under the key selected since, where the next save would write that value to it. An answer is now applied only while its key is still selected in the same suite.
JSON values keep numbers as Double, which holds every integer only below 2^53. A larger one inside a stored container was rounded on the way to the panel, and saving any other row wrote the rounded number back. Such a container is now described rather than encoded, which the panel shows read-only.
heoblitz
approved these changes
Oct 14, 2026
heoblitz
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for your contribution!
Closed
easyhooon
added a commit
to easyhooon/necto
that referenced
this pull request
Oct 16, 2026
JSON numbers are doubles, which hold every integer only below 2^53. A larger Long was listed as an Int, so the panel parsed it into a rounded number and saving the row unchanged stored that number instead: 9007199254740993 became 9007199254740992. Such a Long is now named Long, which the panel leaves read-only, and a write that reaches the plugin anyway is refused. An integer at 2^53 or beyond is refused too, since the number that arrived may already have been rounded. This follows the iOS fix for containers in toss#21.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four related problems in the Preferences plugin and its panel, all reachable from the shipped panel or the CLI (
preferences.setdeclares"value": {}in its manifest, so nothing is rejected before it reaches the app):preferences.setconverted an Int hint withInt(_:), which traps outside the Int range (1e30typed into an Int field), and passednullthrough toUserDefaults.set, which raises an exception for a value that is not a property list (nulltyped into an array row). Both now throw.invalidInput.NectoJSONValue(foundationValue:)matchedNSNumberagainstBoolfirst, and anNSNumbercasts toBoolwhenever it holds 0 or 1. A stored["retryCount": 1]showed astrue, and the next edit of any row saved it back as a Bool. The check is now by type (CFBooleanGetTypeID), asdescribealready does at the top level. Integers above 2^53 are refused for the same reason — aDoublewould round them — so such a container is described rather than encoded, and the panel shows it read-only."1"or"true"came back as a number or a Bool. A container holding aDateorDatais described rather than encoded as JSON, and the panel opened it as an empty editor whose Save replaced the stored value. An emptied number field saved0. Rows now round-trip to the value they showed (src/model.ts, unit-tested), a container that cannot be read is shown read-only, and an empty or unsafe number is refused.Changelog
Fix Preferences crashing the connected app on
nullor an out-of-range Int, and fix container edits changing the types of stored values.Test Plan
swift test: 166 tests in 11 suites passed. New tests:keepsFoundationNumbersThatLookLikeBooleans,refusesFoundationIntegersADoubleCannotHold, "keeps a nested Int an Int when a container is read", "refuses an Int that does not fit", "refuses null at any depth", "describes a container whose integer JSON would round". The nested-Int test fails onmain; the null and Int ones crash the test process onmain(the null case was also reproduced with a standalone script:UserDefaults.set(["a": NSNull()], forKey:)aborts).swift test --package-path NectoMac: 267 tests passed.yarn typecheck,yarn test,node script/check-panel-assets.mjs: passed; the preferences package now has 5 vitest cases formodel.ts.xcodebuild -scheme NectoAppTests test: 28 tests passed (run before the last two commits, which touch only the panel's TypeScript andNectoJSONValue).Sources/NectoDefaultPlugins/Panels/preferencesis the rebuilt output ofyarn build; a fresh build leaves the tree clean.event-log).