WordPress / WordPress/WordPress-Coding-Standards

Detect HTML inside format strings

Open
#1,946 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Enhancement
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

Bug Description

It should be helpful if WPCS detected HTML inside format strings (even if they aren't immediately printed).

Minimal Code Snippet

echo "<a href='" . $url . "'>" . $label . '</a>'; // escaping error detected
echo sprintf( '<a href="%s">%s</a>', $url, $label ); // escaping error detected
$boo = sprintf( '<a href="%s">%s</a>', $url, $label ); // escaping error NOT detected

Error Code

WordPress.Security.EscapeOutput.OutputNotEscaped

Environment

Question Answer
PHP version 7.3.11
PHP_CodeSniffer version 3.5.6
WPCS version 2.3.0
WPCS install type composer project local

Additional Context (optional)

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of WPCS.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal PHP snippet and the WordPress.Security.EscapeOutput.OutputNotEscaped error code, then trace the WPCS sniff that detects escaping errors for echoed and sprintf-generated HTML. Compare the assigned and unassigned sprintf cases, verify behavior against the develop branch, and add coverage showing that HTML in stored format strings is detected.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.