Automattic / Automattic/VIP-Coding-Standards
ProperEscapingFunction: flag printf() usages for placeholders being escaped incorrectly
- Dominant language
- PHP
- Stars
- 261
- Forks
- 44
- Avg merge
- 19m
- Merged PRs (30d)
- 1
Description
## Describe the solution you'd like
When `printf()` is used, we should ensure that the content in the placeholders are correctly escaped.
## What code should be reported as a violation?
```php
printf(
'%s',
esc_url( $class ), // Error.
esc_attr( $url ), // Error.
esc_attr( $content ), // Error.
);
```
```php
printf(
'%s',
esc_html__( $class, 'domain' ), // Error.
esc_url( $url ),
esc_attr_x( $content, $context, 'domain' ), // Error.
);
```
## What code should *not* be reported as a violation?
Correct usages of escaping:
```php
printf(
'%s',
esc_attr( $class ),
esc_url( $url ),
esc_html( $content )
);
```
Correct usages of escaping with translation functions:
```php
printf(
'%s',
esc_attr_x( $class, $context, 'domain' ),
esc_url( $url ),
esc_html__( $content, 'domain' )
);
```
## Additional context
Contributor guide
Research direction
Start by locating the ProperEscapingFunction rule and its handling of printf() calls. Compare the reported and unreported PHP examples in the issue, then find the rule's existing test coverage. Done means incorrectly escaped placeholder arguments are reported while the shown correct escaping and translation-function cases are accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- security, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100