Skip to content

tooling: views escape what they read with raw(), and the backend sample does #79

Closed

Description

@schlessera

Context

Principle 9: values a view reads as properties are escaped by default (src/Infrastructure/View/SimpleView.php:230-250); a value fetched with raw() must be escaped by the template for where it is printed. views/test-backend-service.php:9 prints <?= $this->raw( 'plugin' ) ?> with no escaping, and vendor/bin/phpcs views/test-backend-service.php reports nothing (checked 2026-10-23), so WordPress Coding Standards do not see it. views/test-loop-service.php:7-17 shows the correct pattern: the raw WP_Post is printed field by field through esc_html(). Principle 14 makes a shortcut in a sample a defect.

Scope

  • A PHPStan rule architecture.rawIsEscaped over the production view directories (dependencyDirection.views): every expression printed with echo, print or <?= that contains a $this->raw( … ) call, or a variable assigned from one, must be the argument of a function in rawIsEscaped.escapingFunctions (default: esc_html, esc_attr, esc_url, esc_js, esc_textarea, esc_xml, wp_kses, wp_kses_post, wp_kses_data, absint, intval).
  • Fix views/test-backend-service.php:9 to escape the raw value with esc_html(), keeping it a demonstration of raw() with a comment saying why it is escaped.
  • The message names the template, the line and the escaping function family to use.

Out of scope

Acceptance criteria

  • A fixture template that prints $this->raw( 'x' ) unescaped, and one that prints a variable assigned from it, fail with the full message asserted; esc_html( $this->raw( 'x' ) ) and the property form pass.
  • views/test-backend-service.php escapes its raw value and both views pass.
  • The integration test for the backend sample still passes.

Verification

composer test
composer lint

Impact on generated plugins

Tests and tool configuration only; no interface or convention generated plugins rely on changes. Settings read the plugin's namespace and prefixes from configuration, so a generated plugin keeps the check after renaming.

Activity

  1. added
    type: test
    area: sample
    area: tooling
    priority: p2
    agent-ready
    on Oct 23, 2026
  2. self-assigned this
    on Oct 23, 2026
  3. schlessera commented on Oct 23, 2026

    @schlessera
    MemberAuthor

    Claiming this. Branch: test/79-raw-is-escaped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: samplearea: toolingpriority: p2type: test

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions