Source File
limits.go
Belonging Package
github.com/pancsta/d2/d2renderers/d2latex
package d2lateximport ()const (// MaxInputBytes bounds the work and output that a single LaTeX label can// cause in the embedded MathJax renderer.MaxInputBytes = 4 << 10// MaxGroupNestingDepth prevents deeply nested TeX groups from exhausting// the Go stack in mathjax-go's recursive group parser.MaxGroupNestingDepth = 128)// ValidateInput applies D2's resource limits to a LaTeX label. Render and// Measure both call it so compiler, WASM, and raw render-target paths share// the same admission policy.func ( string) error {if len() > MaxInputBytes {return fmt.Errorf("latex input is %d bytes, exceeding limit %d", len(), MaxInputBytes)}if !utf8.ValidString() {return fmt.Errorf("latex input must be valid UTF-8")}:= 0:= 0:= falsefor := 0; < len(); ++ {:= []if {if == '\n' || == '\r' {= false}continue}if == '\\' {++continue}:= %2 != 0= 0if {continue}switch {case '%':= truecase '{':++if > MaxGroupNestingDepth {return fmt.Errorf("latex group nesting depth %d exceeds limit %d", , MaxGroupNestingDepth)}case '}':if > 0 {--}}}return nil}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |