WordPress / WordPress/WordPress-Coding-Standards

Check for encoding values passed to add_query_arg()

Open
#461 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This is something suitable both for WordPress-VIP and WordPress-Extra:

add_query_arg() is a really useful function, but it might not work as intended.
The values passed to it are not encoded meaning that passing

$m_yurl = 'admin.php?action=delete&post_id=321';
$my_url = add_query_arg( 'my_arg', 'somevalue&post_id=123', $my_url );

You would expect the url to be: admin.php?action=delete&post_id=321&somevalue%26post_id%3D123

But in fact it becomes: admin.php?action=delete&post_id=321&somevalue&post_id=123

Using rawurlencode() on the values passed to it prevents this.
https://vip.wordpress.com/documentation/encode-values-passed-to-add_query_arg/

See https://vip.wordpress.com/documentation/code-review-what-we-look-for/#encoding-values-passed-to-add_query_arg

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 by reading the add_query_arg() behavior described in the issue and the linked WordPress VIP encoding guidance. Identify the PHP_CodeSniffer rule and its existing tests that cover this function, then verify that values containing query delimiters are detected and that the documented encoding expectation is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.