mirror of
https://github.com/semihalev/twig.git
synced 2026-03-14 13:55:46 +01:00
- Implement SecurityPolicy interface with function/filter/tag restrictions - Add DefaultSecurityPolicy with sensible defaults for common operations - Add sandboxed option to include tag for secure template inclusion - Implement context-level sandbox flag and methods - Add engine-level sandbox control methods - Create comprehensive tests for sandbox functionality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package twig
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// TestWhitespaceControl tests the whitespace control with dash modifiers
|
|
func TestWhitespaceControl(t *testing.T) {
|
|
engine := New()
|
|
|
|
tests := []struct {
|
|
name string
|
|
source string
|
|
context map[string]interface{}
|
|
expected string
|
|
}{
|
|
{
|
|
name: "Whitespace control with dash",
|
|
source: "Before{%- if true -%}content{% endif -%}After",
|
|
context: nil,
|
|
expected: "BeforecontentAfter",
|
|
},
|
|
{
|
|
name: "Whitespace control with left dash only",
|
|
source: "Before {%- if true %}content{% endif %} After",
|
|
context: nil,
|
|
expected: "Beforecontent After",
|
|
},
|
|
{
|
|
name: "Whitespace control with right dash only",
|
|
source: "Before {% if true -%}content{% endif -%} After",
|
|
context: nil,
|
|
expected: "Before contentAfter",
|
|
},
|
|
{
|
|
name: "Whitespace control with variable tags",
|
|
source: "Before {{- 'content' -}} After",
|
|
context: nil,
|
|
expected: "BeforecontentAfter",
|
|
},
|
|
{
|
|
name: "Mixed whitespace control",
|
|
source: "Line1\n {{- 'content' }} \n {% if true -%} more {% endif -%}\nLine2",
|
|
context: nil,
|
|
expected: "Line1content \n more Line2",
|
|
},
|
|
{
|
|
name: "Newline control with dash",
|
|
source: "Line1\n{{- 'content' -}}\nLine2",
|
|
context: nil,
|
|
expected: "Line1contentLine2",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := engine.RegisterString(tt.name, tt.source)
|
|
if err != nil {
|
|
t.Fatalf("Error registering template: %v", err)
|
|
}
|
|
|
|
result, err := engine.Render(tt.name, tt.context)
|
|
if err != nil {
|
|
t.Fatalf("Error rendering template: %v", err)
|
|
}
|
|
|
|
if result != tt.expected {
|
|
t.Errorf("Expected %q, got %q", tt.expected, result)
|
|
}
|
|
})
|
|
}
|
|
}
|