Skip to content

WordPress 5.9.0 Restored sanitize_url() as a Proper Method for Sanitizing URLs #2189

@timnolte

Description

@timnolte

Bug Description

When using the sanitize_url it is not recognized as being a proper sanitization method, and recommends esc_url_raw().

Minimal Code Snippet

$postid = ! empty( sanitize_url( $_SERVER['REQUEST_URI'] ) ) ? url_to_postid( sanitize_url( $_SERVER['REQUEST_URI'] ) ) : $context['post']->ID;

The issue happens when running this command:

phpcs ...

... over a file containing this code:

$postid = ! empty( sanitize_url( $_SERVER['REQUEST_URI'] ) ) ? url_to_postid( sanitize_url( $_SERVER['REQUEST_URI'] ) ) : $context['post']->ID;

Error Code

Environment

Question Answer
PHP version 8.0.24
PHP_CodeSniffer version 3.7.1
WPCS version 2.3.0
WPCS install type Composer project local
IDE (if relevant) Neovim

Additional Context (optional)

https://developer.wordpress.org/reference/functions/sanitize_url/#changelog

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of WPCS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions