Description
config::to_bool() is meant to lowercase its input, but it uses std::for_each with a lambda that returns the lowered character. for_each discards that return value, so the string is never changed (src/config.cpp#L1335-L1338). As a result, capitalised values such as Enabled, True, On or Yes in a hand-edited sunshine.conf are read as false. Lowercase spellings and anything containing a 1 work, and the web UI uses lowercase values, which is probably why this went unnoticed.
This PR uses std::transform so the lowercased characters are written back, and takes the character as unsigned char so std::tolower is well-defined for non-ASCII bytes.
Screenshot
n/a
Issues Fixed or Closed
None filed.
Roadmap Issues
None.
Testing
- Added
ConfigPersistenceTest.ParsesBooleanOptionsCaseInsensitivelyintests/unit/test_config.cpp. It feedsEnabled,TRUE,On,Yes,Disabled,FalseandOFFthroughconfig::apply_config_for_testfor the existingfp16_sdr_gamma_encodedoption, following the neighbouringParsesFp16SdrGammaEncodedOptiontest. With the old code the four capitalised "true" cases would fail, as the standalone check below showsto_boolreturning false for them. - I extracted the (identical)
to_boolbody and compiled it standalone before and after the change (g++ 13):Enabled,TRUE,Onreturn false before and true after;yes,no,Off,1,Falseare unchanged. - Not run: I could not build Sunshine locally, so the new unit test and the full suite have only been checked by reading, not executed. I am relying on CI for that.
Type of Change
- feat: New feature (non-breaking change which adds functionality)
- fix: Bug fix (non-breaking change which fixes an issue)
- docs: Documentation only changes
- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
- refactor: Code change that neither fixes a bug nor adds a feature
- perf: Code change that improves performance
- test: Adding missing tests or correcting existing tests
- build: Changes that affect the build system or external dependencies
- ci: Changes to CI configuration files and scripts
- chore: Other changes that don't modify src or test files
- revert: Reverts a previous commit
- BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)
Checklist
- Code follows the style guidelines of this project
- Code has been self-reviewed
- Code has been commented, particularly in hard-to-understand areas
- Code docstring/documentation-blocks for new or existing methods/components have been added or updated
- Tests have been added or updated for new or modified functionality, including regression tests for bug fixes
AI Usage
See our AI usage policy.
- AI tools were used while preparing this PR
An AI-assisted code review found the bug; the fix, the test and this description were written with AI help and checked against the source.
Activity
5❌ The last analysis has failed.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
See analysis details on SonarQube Cloud