#5989

fix(config): make boolean parsing case-insensitive

OpenPressimizewants to merge intofrom

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.ParsesBooleanOptionsCaseInsensitively in tests/unit/test_config.cpp. It feeds Enabled, TRUE, On, Yes, Disabled, False and OFF through config::apply_config_for_test for the existing fp16_sdr_gamma_encoded option, following the neighbouring ParsesFp16SdrGammaEncodedOption test. With the old code the four capitalised "true" cases would fail, as the standalone check below shows to_bool returning false for them.
  • I extracted the (identical) to_bool body and compiled it standalone before and after the change (g++ 13): Enabled, TRUE, On return false before and true after; yes, no, Off, 1, False are 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.