Skip to content

feat(allowlist): add Pug template support - #1114

Merged
lizhengfeng101 merged 1 commit into
alibaba:mainfrom
dvd233:feat/pug-template-support
Aug 31, 2026
Merged

feat(allowlist): add Pug template support#1114
lizhengfeng101 merged 1 commit into
alibaba:mainfrom
dvd233:feat/pug-template-support

Conversation

@dvd233

@dvd233 dvd233 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add .pug to the case-insensitive supported-extension allowlist;
  • route Pug templates to a dedicated review rule covering escaping contexts, attribute spreads and URL sinks, server-side template trust, embedded client data, includes/inheritance/mixins/filters, indentation and whitespace, accessibility, and hot-path compilation;
  • preserve the existing generic fixture exclusions without adding a broad Pug-only test-directory exclusion;
  • add lower- and upper-case allowlist and resolver coverage, including ResolveDetail metadata and rule-content assertions.

Why a dedicated rule

Pug compiles JavaScript-backed, indentation-sensitive templates to HTML. Its safe defaults are context-specific: #{} / = and ordinary attributes are HTML-escaped, while !{} / != and general &attributes(object) spreads cross explicit raw-output boundaries. HTML escaping also does not make values safe inside JavaScript, CSS, URLs, or event handlers.

The rule therefore aims for high-signal findings while explicitly suppressing common false positives, including ordinary escaped text interpolation and the already-escaped implicit mixin attributes object.

Validation

  • make test
  • make check
  • make build
  • built CLI: ocr rules check views/account.pug
  • built CLI: ocr rules check VIEWS/ACCOUNT.PUG

All commands passed with Go 1.25.5. The runtime checks matched Source: System built-in, Pattern: **/*.pug, and the dedicated Pug rule for both path casings.

Self-review

ocr review --preview initially exposed the repository's default exclusion of test files and unsupported rule-doc extensions. A temporary, repository-external include rule then confirmed all 5 changed files were selected with 0 exclusions. LLM-backed ocr review could not dispatch because this environment has no OCR LLM endpoint configured, so I used ocr delegate to produce the complete 5-file rules/background bundle and performed separate Standards and Spec passes; both produced 0 findings.

Closes #1113
Part of #470

AI assistance disclosure

Codex was used to inspect repository conventions, cross-check the rule against Pug's official language/API documentation and security guidance, draft the implementation and tests, run validation, and review the final diff. I verified the final file set, behavior, test logs, commit, and remote branch before submission.

Allow Pug templates, route them to a dedicated review rule, and cover case-insensitive resolution plus fixture exclusion boundaries.

Refs alibaba#1113
@github-actions

Copy link
Copy Markdown
Contributor

OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s).

Comment on lines +179 to +181
{"pug fixture", "test/fixtures/page.pug", true},
{"pug template in tests directory", "tests/templates/page.pug", false},
{"pug template in test directory", "test/templates/page.pug", false},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What evidence made you think the wanted is false? Is there a exclude patterrn?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the site documentation, people forget this every time.

Comment on lines +912 to +943
func TestResolveDetail_SystemPugPatternMatch(t *testing.T) {
setTestHome(t, t.TempDir())
resolver, _, err := NewResolver(t.TempDir(), "", ResolverOptions{})
if err != nil {
t.Fatalf("NewResolver: %v", err)
}
dr := resolver.(DetailResolver)

for _, path := range []string{"index.pug", "views/account/profile.pug", "VIEWS/INDEX.PUG"} {
t.Run(path, func(t *testing.T) {
detail := dr.ResolveDetail(path)
if detail.Source != "system" {
t.Errorf("expected source 'system', got %q", detail.Source)
}
if detail.Pattern != "**/*.pug" {
t.Errorf("expected pattern '**/*.pug', got %q", detail.Pattern)
}
for _, required := range []string{
"Pug Escaping and Output Contexts",
"server-side template injection",
"&attributes",
"compileClient",
"Accessibility",
} {
if !strings.Contains(detail.Rule, required) {
t.Errorf("expected Pug rule to contain %q", required)
}
}
})
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt if this test is necessary @dvd233 , but OK for improving coverage.

@Qiyuanqiii Qiyuanqiii left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes because the new built-in **/*.pug -> pug.md route is not reflected in the public review-rules documentation. Please update pages/src/content/docs/{en,zh,ja,ko,ru}/review-rules.md in the same matching order so the documented built-in rules stay aligned with runtime behavior, consistent with #1086. The allowlist and resolver changes otherwise look good.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 8d023aa into alibaba:main Aug 31, 2026
13 checks passed
@wu21-web

Copy link
Copy Markdown
Contributor

@lizhengfeng101 Merge without documentation?

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Merge without documentation?

Pug usage is declining and is primarily found in legacy codebases, so it need not be included in the rules documentation.

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.

feat(allowlist): add Pug template support

4 participants