[2.x] fix: keep a saved falsy setting in settings modals too - #4901
Merged
Conversation
#4782 fixed this in `AdminPage` but the identical line in `SettingsModal` survived, so the bug still reached every settings *modal*: settings live in a string column, a saved `false` arrives as an empty string, and choosing the fallback on falsiness discarded it and reseeded the default. A boolean setting whose default is truthy could not be switched off — it came back on with every reload. `SettingsModal` is public API, imported by extensions as `flarum/admin/components/SettingsModal`, and core's custom header, footer and CSS modals extend it, as does flarum/audit. The existing test file now covers both classes side by side rather than only the one the original issue named, which is what would have caught this the first time. Its docblock is corrected too: it claimed a saved `'0'` was also discarded, but the string is truthy in JavaScript, unlike the number — the empty string is the only value a setting can hold that JavaScript reads as absent.
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.
Follow-up to #4782, which fixed this in
AdminPagewhile the identical line inSettingsModalsurvived. Same defect, different file — context in #4781.Settings live in a string column, so a saved
falsearrives as an empty string. Choosing the fallback on falsiness discarded it and reseeded the default, which meant a boolean setting whose default is truthy could not be switched off — it came back on with every reload.Why it matters
SettingsModalis public API — extensions import it asflarum/admin/components/SettingsModal. Current consumers:EditCustomHeaderModal,EditCustomFooterModal,EditCustomCssModalflarum/audit:LimitedSettingsModalTests
The existing
AdminPageSetting.test.ts(added in #4782) now covers both classes side by side rather than only the one the original issue named — which is what would have caught this the first time round. Seven tests: four forAdminPage, three forSettingsModal.I checked the new
SettingsModalempty-string test fails without this change.Its docblock is also corrected. It claimed a saved
'0'was discarded too, but the string'0'is truthy in JavaScript — only the number is falsy. The empty string is the only value a setting can hold that JavaScript reads as absent.All integration suites green: 50 suites, 169 tests.
check-typingsclean.Testing by hand
Awkward to demonstrate in core, since none of the three core modals has a boolean setting with a truthy default — the visible effect there is nil. It reproduces through an extension that puts such a setting in a modal. The test coverage is the real assurance here.