Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic autoescape="strict" support #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const (
AutoescapeOn
AutoescapeOff
AutoescapeContextual
AutoescapeStrict
)

// TemplateNode holds a template body.
Expand Down
10 changes: 8 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ The goal is full compatibility and feature parity with the official Closure
Templates project.

The server-side templating functionality is well tested and nearly complete,
except for two notable areas: contextual autoescaping and
internationalization/bidi support. Contributions welcome.
except for a few notable areas:

* contextual autoescaping
* strict autoescaping enforcement
* internationalization/bidi support
* strongly-typed parameter declarations (via the `{@param}` command)

Contributions to address these shortcomings are welcome.

The Javascript generation is early and lacks many generation options, but
it successfully passes the server-side template test suite. Note that it is
Expand Down
2 changes: 2 additions & 0 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ func (t *tree) parseAutoescape(attrs map[string]string) ast.AutoescapeType {
return ast.AutoescapeOn
case "false":
return ast.AutoescapeOff
case "strict":
return ast.AutoescapeStrict
default:
t.errorf(`expected "true", "false", or "contextual" for autoescape, got %q`, val)
}
Expand Down
2 changes: 1 addition & 1 deletion soyhtml/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (t Renderer) Execute(wr io.Writer, obj data.Map) (err error) {

var autoescapeMode = tmpl.Namespace.Autoescape
if autoescapeMode == ast.AutoescapeUnspecified {
autoescapeMode = ast.AutoescapeOn
autoescapeMode = ast.AutoescapeStrict
}

var initialScope = newScope(obj)
Expand Down