Skip to content

CHAINS-0 envconfig: trim whitespace around map keys/values in reflect path - #2

Open
paxos-hoplites-agent[bot] wants to merge 1 commit into
masterfrom
hoplites/nickg/aW9qdJ7y-trim-map-whitespace
Open

paxos-hoplites-agent[bot] wants to merge 1 commit into
masterfrom
hoplites/nickg/aW9qdJ7y-trim-map-whitespace

Conversation

@paxos-hoplites-agent

Copy link
Copy Markdown

Summary

Plain map[K]V envconfig fields go through the reflection path in processField, which splits on , and : with no strings.TrimSpace. YAML folded block scalars (>-) fold newlines into spaces, so a multi-line map value such as:

CHAINS_ENABLED: >-
  NETWORK_ETH:true,
  NETWORK_BTC:true

arrives as NETWORK_ETH:true, NETWORK_BTC:true — with a leading space before NETWORK_BTC. Without trimming, " NETWORK_BTC" becomes a distinct key and lookups for the intended key silently miss (e.g. recon quietly stops running for that chain).

Fields backed by a custom Decode() method were already safe because their decoders trim. This brings plain-map fields to parity by trimming both the key and the value in the reflect.Map path — fixing every map field at once rather than requiring per-field typed aliases in each consumer.

Context: paxosglobal/pax#60519 (comment).

Changes

  • envconfig.go — trim whitespace around the key and value when decoding map entries in the reflection path
  • envconfig_test.goTestMapFieldWhitespaceTrimmed covering space-after-comma (the YAML >- case), space around the colon, and leading/trailing whitespace

Plain map[K]V envconfig fields go through the reflection path in
processField, which splits on "," and ":" with no TrimSpace. YAML folded
block scalars (>-) fold newlines into spaces, so a multi-line map value
such as:

    CHAINS_ENABLED: >-
      NETWORK_ETH:true,
      NETWORK_BTC:true

arrives as "NETWORK_ETH:true, NETWORK_BTC:true" — with a leading space
before NETWORK_BTC. Without trimming, " NETWORK_BTC" becomes a distinct
key and lookups for the intended key silently miss.

Fields backed by a custom Decode() method were already safe because
their decoders trim; this brings plain-map fields to parity by trimming
both key and value in the reflect.Map path, covering every map field at
once rather than requiring per-field typed aliases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Co-Authored-By: Nick Geib <nicholas.geib@paxos.com>
@paxos-hoplites-agent
paxos-hoplites-agent Bot force-pushed the hoplites/nickg/aW9qdJ7y-trim-map-whitespace branch from 3ff581f to 7dcfca2 Compare July 17, 2026 23:53
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.

0 participants