Quoted value followed by an inline comment keeps its literal quotes
The finding
Quotes are only stripped when the whole remaining value starts and ends with the same quote character. Take a line like TOKEN="abc" # prod token. The last character is n, not a quote, so the quote-stripping branch is skipped. The else branch then removes the #... comment and leaves "abc", with the quote characters still in the value. For a token, password or URL, this silently produces a wrong config value. The result is failed auth or failed connections, and the cause is not obvious. Common dotenv implementations support KEY="value" # comment.
1| """The one config file: every other file scout reads, every service URL, and the schedule.
2|
3| ``scout.yaml`` is validated by :class:`ScoutConfig` (pydantic v2, unknown keys rejected at every level).
4| Relative paths in it resolve against the config file's own directory, so a config directory can be moved
5| or mounted anywhere.
6|
7| **Secrets never live in the YAML.** The file names an environment variable (``token_env: SCOUT_API_TOKEN``)
8| and :func:`resolve_secret` reads it from the process environment. :func:`load_config` first loads a
9| ``.env`` file beside the config into the environment, without overriding variables that are already set,
10| so a real environment always wins over the file. Resolved values come back as :class:`~pydantic.SecretStr`
11| and the config model itself holds only variable *names*, so neither its repr nor its dumps can leak one.
12|
13| **Strict here, forgiving there.** The two kinds of config fail differently, on purpose:
14|
15| - This top-level file is read once at startup, and :func:`load_config` raises :class:`ConfigError` on
16| anything wrong with it (missing file, bad YAML, unknown key, bad value). Scout refuses to start on a
17| broken config rather than guess at what you meant.
18| - The files it names (heartbeat policy, standing approvals, tariff, signal rules) are reloaded while scout
19| runs, and a bad edit to one of those degrades to defaults (or skips the bad rule) and is reported, so a
20| typo can't stop status updates. See :mod:`argus_scout.heartbeat`, :mod:`argus_scout.approvals` and
21| :mod:`argus_scout.signals`.
22| """
23|
24| from __future__ import annotations
25| The work pack
Recommendation. Strip the inline comment before checking for quotes, but only outside quotes. For example: if the value starts with a quote, find the matching closing quote. Take the text between the quotes and ignore anything after the closing quote if it is whitespace or a # comment. Otherwise, apply the # split.
Acceptance criteria
- Address: Quoted value followed by an inline comment keeps its literal quotes
- Keep the change scoped to the cited file/symbols unless impact requires otherwise
- Strip the inline comment before checking for quotes, but only outside quotes. For example: if the value starts with a quote, find the matching closing quote. Take the text between the quotes and ignore anything after the closing quote if it
- Re-check
src/argus_scout/config.pyafter the fix
Status
- claimed
- resolved
The fix
6826e07318 fix: .env quoted values followed by an inline comment lose their quotes.
@@ -879,8 +879,10 @@ def parse_env_file(path: Path) -> dict[str, str]: key, value = key.strip(), value.strip() if not sep or not _ENV_NAME.match(key): continue- if len(value) >= 2 and value[0] == value[-1] and value[0] in "'\"":- value = value[1:-1]+ end = value.find(value[0], 1) if value[:1] in ("'", '"') else -1+ rest = value[end + 1 :].lstrip() if end > 0 else None+ if rest is not None and (not rest or rest.startswith("#")):+ value = value[1:end] # KEY="value" # comment: the quotes and the comment go else: value = value.split(" #", 1)[0].rstrip() values[key] = value@@ -202,6 +202,12 @@ def test_a_secret_where_its_env_name_belongs_never_appears_in_the_error(): assert SECRET not in text +def test_parse_env_file_quoted_value_with_an_inline_comment(tmp_path):+ path = tmp_path / ".env"+ path.write_text('A="abc" # prod token\nB=\'x # y\' #c\nC="open\nD="a"b\nE=\'\'\n')+ assert parse_env_file(path) == {"A": "abc", "B": "x # y", "C": '"open', "D": '"a"b', "E": ""}++ def test_parse_env_file(tmp_path): path = tmp_path / ".env" path.write_text('A=1\n\n# no\nB = "two words"\nC=plain # trailing comment\nnot a line\n1BAD=x\nD=\n')How it was judged
Proven 1 test(s) fail on dev and pass with the fix: tests/test_config.py::test_parse_env_file_quoted_value_with_an_inline_comment
Judged 24 Nov 2026, 04:50 UTC against dev at d0c0f66.
| Test | on dev | dev + patch |
|---|---|---|
tests/test_config.py::test_parse_env_file_quoted_value_with_an_inline_comment | failed | passed |
The other 14 tests in the run (14 with the same result on both trees)
tests/test_config.py::test_check_config_checks_named_files | passed | passed |
tests/test_config.py::test_check_config_fails_on_missing_or_bad_file | passed | passed |
tests/test_config.py::test_check_config_rejects_invalid | passed | passed |
tests/test_config.py::test_config_is_immutable | passed | passed |
tests/test_config.py::test_empty_config_is_all_defaults | passed | passed |
tests/test_config.py::test_entries_commented_out_at_any_depth_read_as_empty | passed | passed |
tests/test_config.py::test_full_config | passed | passed |
tests/test_config.py::test_init_into_directory_then_check | passed | passed |
tests/test_config.py::test_init_writes_refuses_and_forces | passed | passed |
tests/test_config.py::test_missing_config_raises | passed | passed |
tests/test_config.py::test_parse_env_file | passed | passed |
tests/test_config.py::test_secrets_resolve_from_dotenv_and_never_appear | passed | passed |
tests/test_config.py::test_serve_refuses_invalid_config | passed | passed |
tests/test_config.py::test_starter_loads_with_defaults | passed | passed |