Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_escaped, _safe or _clean #2440

Closed
hupe13 opened this issue Apr 3, 2024 · 2 comments
Closed

_escaped, _safe or _clean #2440

hupe13 opened this issue Apr 3, 2024 · 2 comments

Comments

@hupe13
Copy link

hupe13 commented Apr 3, 2024

Developer Handbook says:

In situations like this, always escape while creating the string and store the value in a variable that is a postfixed with _escaped, _safe or _clean (e.g., $variable becomes $variable_escaped or $variable_safe).

My code:

			if ( $settings['track'] == 'filename' ) {
				$path_parts = pathinfo( $gpx );
				$switchname_escaped = '"' . $path_parts['filename'] . '"';
			} else {
				$switchname_escaped = 'e.name';
			}
			echo '
			controlElevation.on("eledata_loaded", function(e) {
				switchtrack.addOverlay(e.layer, ' . $switchname_escaped . ');
			});
			';

phpcs says:

886 | ERROR | [ ] All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$switchname_escaped'.

The same is with '$switchname_safe'.

Am I misunderstanding this or is it a bug?

@dingo-d
Copy link
Member

dingo-d commented Apr 3, 2024

No, it's not a bug. We don't do selective escaping based on the name of the variable. PHPCS cannot know if your variable is safe or not (unless it's escaped at the point of output), so it will output the error.

@hupe13
Copy link
Author

hupe13 commented Apr 3, 2024

Thank you for clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants