Automattic / Automattic/VIP-Coding-Standards

ProperEscapingFunction: flag printf() usages for placeholders being escaped incorrectly

未关闭
#674 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Type: Enhancement
主要语言
PHP
星标
261
派生
44
平均合并
19 分钟
30 天内合并 PR
1

描述

## 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

贡献指南

打开贡献指南

调研方向

首先定位 ProperEscapingFunction 规则及其对 printf() 调用的处理。比较 issue 中已报告和未报告的 PHP 示例,然后查找该规则现有的测试覆盖。完成的标准是:错误转义的占位符参数会被报告,而所示的正确转义和翻译函数案例会被接受。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
security, tooling
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。