Skip to content

d2svg: reject padding with negative dimensions - #2841

Merged
alixander merged 1 commit into
masterfrom
agent/fix-negative-padding
Aug 10, 2026
Merged

d2svg: reject padding with negative dimensions#2841
alixander merged 1 commit into
masterfrom
agent/fix-negative-padding

Conversation

@alixander

Copy link
Copy Markdown
Collaborator

Summary

  • preserve valid negative padding as a supported way to crop the viewport
  • reject padding that would overflow platform integers or produce a negative SVG width or height
  • preserve zero-sized dimensions, which SVG treats as non-rendering rather than invalid

Before this change, for example, d2 --pad=-1000 could succeed while emitting negative width, height, and viewBox dimensions. SVG 2 treats negative width or height as illegal: https://www.w3.org/TR/SVG2/struct.html

Validation

  • go test ./d2renderers/d2svg -count=1
  • go test -race ./d2renderers/d2svg -run '^TestRenderValidatesPaddingDimensions$' -count=20
  • go vet ./d2renderers/d2svg
  • GOOS=js GOARCH=wasm go test -c ./d2renderers/d2svg
  • go test ./e2etests -run '^TestE2E$' -count=1 -parallel=1
  • CLI controls: --pad=-1 renders; --pad=-1000 returns an error

The regression covers a valid negative crop, the exact zero-dimension boundary, the first invalid negative value, and minimum/maximum int64 inputs.

@alixander
alixander force-pushed the agent/fix-negative-padding branch 3 times, most recently from 77339e6 to fd5fbe0 Compare August 10, 2026 01:46
Signed-off-by: Alexander Wang <alex@terrastruct.com>
@alixander
alixander force-pushed the agent/fix-negative-padding branch from fd5fbe0 to 59e4472 Compare August 10, 2026 01:50
@alixander
alixander marked this pull request as ready for review August 10, 2026 01:52
@alixander
alixander merged commit bbb2add into master Aug 10, 2026
6 checks passed
@alixander
alixander deleted the agent/fix-negative-padding branch August 10, 2026 01: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.

1 participant