Skip to content

compiler: reject non-finite opacity values - #2840

Merged
alixander merged 1 commit into
masterfrom
agent/fix-nonfinite-opacity
Aug 10, 2026
Merged

compiler: reject non-finite opacity values#2840
alixander merged 1 commit into
masterfrom
agent/fix-nonfinite-opacity

Conversation

@alixander

Copy link
Copy Markdown
Collaborator

What changed

  • reject non-finite style.opacity values at the existing style validation boundary
  • preserve the existing source-located diagnostic for values outside 0.0–1.0
  • cover case-insensitive NaN, signed Inf/Infinity, and valid 0, 0.5, and 1 controls
  • document the bugfix in the next changelog

Why

strconv.ParseFloat accepts NaN. The existing range check used only f < 0 || f > 1, and both comparisons are false for NaN. That allowed NaN into the exported target graph, where JSON marshaling failed later with json: unsupported value: NaN instead of reporting the invalid source value.

The validation now explicitly rejects NaN and infinities before storing the opacity.

User impact

Invalid opacity values now fail at their D2 source location with the normal opacity diagnostic. Valid opacity values render exactly as before.

Validation

  • go test ./d2graph ./d2compiler -count=1
  • go test -race ./d2compiler -run '^TestOpacityValidation$' -count=1
  • go vet ./d2graph ./d2compiler
  • go test ./e2etests -run '^TestE2E$' -count=1
  • git diff --check

Signed-off-by: Alexander Wang <alex@terrastruct.com>
@alixander
alixander force-pushed the agent/fix-nonfinite-opacity branch from b845478 to 0964ad0 Compare August 10, 2026 01:35
@alixander
alixander marked this pull request as ready for review August 10, 2026 01:41
@alixander
alixander merged commit 6afa386 into master Aug 10, 2026
6 checks passed
@alixander
alixander deleted the agent/fix-nonfinite-opacity branch August 10, 2026 01:41
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.

1 participant