alleyinteractive / alleyinteractive/alley-coding-standards

Add a sniff for dynamic keys passed to get_block_wrapper_attributes

Abierto
#76 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
PHP
Estrellas
7
Forks
0
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### Description

Keys provided to the `get_block_wrapper_attributes` function are turned into attribute names, and are not escaped. That's fine if we're specifying a hardcoded value and that hardcoded value is known to be safe, like:

```php
echo get_block_wrapper_attributes( [ 'data-my-key' => $my_value ] );
```

Values are already escaped via `esc_attr` in `get_block_wrapper_attributes`, so dynamic values are okay there.

However, if there is a dynamic key, like:

```php
$attributes[ $my_key ] = $my_value;
echo get_block_wrapper_attributes( $attributes );
```

We should flag that, because the key is dynamic and isn't escaped. Escaping should be done by `sanitize_key`.

### Use Case

When a user uses the `get_block_wrapper_attributes` function, phpcs should throw an error if the user has a dynamic key that is unescaped.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.