Skip to content

fix(config): exclude inline comments and trailing whitespace from values - #6190

Closed
Dev-next-gen wants to merge 1 commit into
SunshineStream:masterfrom
Dev-next-gen:fix/config-inline-comment-values
Closed

Dev-next-gen wants to merge 1 commit into
SunshineStream:masterfrom
Dev-next-gen:fix/config-inline-comment-values

Conversation

@Dev-next-gen

Copy link
Copy Markdown
Contributor

Description

parse_option computes endc, the end of the value without an inline comment or trailing whitespace, but only uses it to find the =. The value itself is copied up to the end of the line, and to_string strips the # comment but keeps the spaces before it. In sunshine.conf:

  • upnp = enabled # open ports gives "enabled ", which to_bool treats as false, so UPnP stays off
  • min_threads = 2 # cores is parsed as 4, because from_view reads the trailing space as a digit
  • port = 48000 # web gives a number outside the allowed range, so the port silently stays at the default
  • port = 48000 (a trailing space, no comment) does the same

The fix copies a single-line value up to endc. Lists still end at the closing bracket found by skip_list, as before. The same values are returned by /api/config, which also reads the file through parse_config.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

Added ConfigParsingTest.ValuesExcludeTrailingCommentsAndWhitespace (inline comment, trailing spaces and tab, CRLF line, and a list followed by a comment).

I did not build test_sunshine for this change. Instead I compiled src/utility.h together with parse_config and its helpers, to_bool and parse_config_integer copied unchanged from src/config.cpp (master, then this branch) with g++ 14 on Linux, and fed them the same input as the new test:

  • on master: 6 failures (upnp is "enabled " and to_bool returns false, port is "47989 \t" and parses as 4798701, encoder is "software\t", min_threads = 2 # cores parses as 4)
  • with the fix: all checks pass, and the list value is [a, b] in both cases

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

Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.5.

This PR was generated by Claude Code, Claude Opus 5.5, low thinking level

parse_option found the end of the value without the comment or trailing
whitespace (endc), but copied the value up to the end of the line.
A line such as `upnp = enabled # comment` produced "enabled ", which
to_bool treats as false, and `min_threads = 2 # comment` was parsed as 4.
@Dev-next-gen

Copy link
Copy Markdown
Contributor Author

This PR was generated by Claude Code, Claude Opus 5.5, low thinking level

@sonarqubecloud

Copy link
Copy Markdown

@ReenigneArcher

Copy link
Copy Markdown
Member

I'm planning to rewrite the config system soon, and this won't apply... so, closing.

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