alleyinteractive / alleyinteractive/alley-coding-standards

Add a sniff for dynamic keys passed to get_block_wrapper_attributes

Aperta
#76 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
PHP
Stelle
7
Fork
0
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start from the project’s existing PHPCS sniffs and find how they inspect function calls and array keys. The target behavior is for calls to get_block_wrapper_attributes to flag dynamic attribute keys that are not sanitized, while allowing hardcoded keys and dynamic values. Done means PHPCS reports the unsafe dynamic-key case described in the issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
php, wordpress
Ambito
security, tooling
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.