Skip to content

fix: keep Preferences from crashing the app or changing the types of stored values - #21

Merged
heoblitz merged 5 commits into
toss:mainfrom
wjdtjq6:fix/preferences-value-integrity
Oct 14, 2026
Merged

heoblitz merged 5 commits into
toss:mainfrom
wjdtjq6:fix/preferences-value-integrity

Conversation

@wjdtjq6

@wjdtjq6 wjdtjq6 commented Oct 13, 2026

Copy link
Copy Markdown

Summary

Four related problems in the Preferences plugin and its panel, all reachable from the shipped panel or the CLI (preferences.set declares "value": {} in its manifest, so nothing is rejected before it reaches the app):

  1. The connected app crashes. preferences.set converted an Int hint with Int(_:), which traps outside the Int range (1e30 typed into an Int field), and passed null through to UserDefaults.set, which raises an exception for a value that is not a property list (null typed into an array row). Both now throw .invalidInput.
  2. Nested 0 and 1 become Booleans. NectoJSONValue(foundationValue:) matched NSNumber against Bool first, and an NSNumber casts to Bool whenever it holds 0 or 1. A stored ["retryCount": 1] showed as true, and the next edit of any row saved it back as a Bool. The check is now by type (CFBooleanGetTypeID), as describe already does at the top level. Integers above 2^53 are refused for the same reason — a Double would round them — so such a container is described rather than encoded, and the panel shows it read-only.
  3. Container edits change or drop values. Saving an Array or Dictionary re-parsed every row from its text, so a stored string "1" or "true" came back as a number or a Bool. 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 (src/model.ts, unit-tested), a container that cannot be read is shown read-only, and an empty or unsafe number is refused.
  4. A late answer lands on another key. Selecting two keys in quick succession could show the first key's value under the second key's name, where the next save would write it. The panel now applies an answer only while its key is still selected, as the Events panel already does.

Changelog

Fix Preferences crashing the connected app on null or 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 on main; the null and Int ones crash the test process on main (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 for model.ts.
  • xcodebuild -scheme NectoAppTests test: 28 tests passed (run before the last two commits, which touch only the panel's TypeScript and NectoJSONValue).
  • Sources/NectoDefaultPlugins/Panels/preferences is the rebuilt output of yarn build; a fresh build leaves the tree clean.
  • Not verified in the running app: the stale-selection guard (the panels have no DOM test harness; it follows the pattern in event-log).

소정섭 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 heoblitz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@heoblitz
heoblitz merged commit d1d6f2d into toss:main Oct 14, 2026
5 checks passed
@easyhooon easyhooon mentioned this pull request Oct 14, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants