WordPress / WordPress/WordPress-Coding-Standards

Add sniff to detect double quotes in database queries

Open
#1,332 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

After receiving a report from a user that has the following MySQL configuration: sql-mode=ANSI_QUOTES, we realised that having double quotes in a query can cause problems.

This is a non-common situation, but as it should be easily detected, we think it will enhance the testing suite.

There are two solutions to resolve this problem:

  1. Using wpdb->prepare to inject the data, with %s (without quotes) approach
  2. Using single quotes

Related: https://github.com/Yoast/wordpress-seo/issues/9237

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

No file, test, or entry point is named in the issue. Start by locating the existing query-related sniffs and their tests, then define completion as detecting problematic double quotes in database queries and covering the behavior in the test suite.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.