Summary
Add support for a file-level directive to control strict mode in Herb::Engine.
Background
The engine already supports a strict option that gets passed to the parser:
# lib/herb/engine.rb
@strict = properties.fetch(:strict, false)
parse_result = ::Herb.parse(input, track_whitespace: true, strict: @strict)
What strict mode controls
In the parser (src/parser.c), strict mode affects HTML tag matching behavior:
strict: true - Reports errors for omitted closing tags (e.g., <p>text without </p>)
strict: false - Silently handles omitted closing tags without errors (following HTML5 optional closing tag rules)
This is useful because HTML5 allows optional closing tags for elements like <p>, <li>, <td>, etc.
Proposed Directive Format
<%# herb:strict false %> <!-- disable strict mode for this file -->
<%# herb:strict true %> <!-- enable strict mode for this file -->
Use Cases
- Legacy templates - Files with valid HTML5 that omit optional closing tags
- Migration - Gradually enable strict mode across a codebase
- Third-party templates - Templates that can't be easily modified but are valid HTML
Relationship to Security Directive
This is separate from <%# herb:security false %> (#1161):
| Directive |
Controls |
herb:strict |
Parser strictness (omitted closing tag errors) |
herb:security |
Security validation (injection pattern errors) |
Summary
Add support for a file-level directive to control strict mode in
Herb::Engine.Background
The engine already supports a
strictoption that gets passed to the parser:What
strictmode controlsIn the parser (
src/parser.c), strict mode affects HTML tag matching behavior:strict: true- Reports errors for omitted closing tags (e.g.,<p>textwithout</p>)strict: false- Silently handles omitted closing tags without errors (following HTML5 optional closing tag rules)This is useful because HTML5 allows optional closing tags for elements like
<p>,<li>,<td>, etc.Proposed Directive Format
Use Cases
Relationship to Security Directive
This is separate from
<%# herb:security false %>(#1161):herb:strictherb:security