Skip to content

_escaped, _safe or _clean #2440

@hupe13

Description

@hupe13

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions