Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class ProperEscapingFunctionSniff extends Sniff {
*/
private $in_short_echo = false;

/**
* Keep track of the current file, so we can reset $in_short_echo for each new file.
*
* @var string Absolute file name of the file being processed. Defaults to an empty string.
*/
private $current_file = '';

/**
* Returns an array of tokens this test wants to listen for.
*
Expand All @@ -119,6 +126,12 @@ public function register() {
* @return void
*/
public function process_token( $stackPtr ) {
// Reset short echo context tracking variable for a new file.
if ( $this->phpcsFile->getFilename() !== $this->current_file ) {
$this->in_short_echo = false;
$this->current_file = $this->phpcsFile->getFilename();
}

/*
* Short open echo tags will act as an echo for the first expression and
* allow for passing multiple comma-separated parameters.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
/*
* This is part one of a two-part test. It must be in a lower-numbered file
* than part two, to trigger the bug in
* https://github.com/Automattic/VIP-Coding-Standards/issues/739
*/
?>
<?= esc_attr('short_tag') ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/*
* This is part two of a two-part test. It must be in a higher-numbered file
* than part one, to trigger the bug in
* https://github.com/Automattic/VIP-Coding-Standards/issues/739
*/
printf(
'<div class="%1$s"><p>%2$s</p></div>',
esc_attr($class),
wp_kses_post($message)
);
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,51 @@ class ProperEscapingFunctionUnitTest extends AbstractSniffUnitTest {
/**
* Returns the lines where errors should occur.
*
* @param string $testFile The name of the file being tested.
*
* @return array <int line number> => <int number of errors>
*/
public function getErrorList() {
return [
3 => 1,
5 => 1,
15 => 1,
17 => 1,
21 => 1,
23 => 1,
33 => 1,
37 => 1,
41 => 1,
45 => 1,
48 => 1,
62 => 1,
63 => 1,
64 => 1,
65 => 1,
67 => 1,
68 => 1,
69 => 1,
72 => 1,
73 => 1,
74 => 1,
75 => 1,
76 => 1,
77 => 1,
78 => 1,
79 => 1,
80 => 1,
82 => 1,
92 => 1,
97 => 1,
102 => 1,
104 => 1,
];
public function getErrorList( $testFile = '' ) {
switch ( $testFile ) {
case 'ProperEscapingFunctionUnitTest.1.inc':
return [
3 => 1,
5 => 1,
15 => 1,
17 => 1,
21 => 1,
23 => 1,
33 => 1,
37 => 1,
41 => 1,
45 => 1,
48 => 1,
62 => 1,
63 => 1,
64 => 1,
65 => 1,
67 => 1,
68 => 1,
69 => 1,
72 => 1,
73 => 1,
74 => 1,
75 => 1,
76 => 1,
77 => 1,
78 => 1,
79 => 1,
80 => 1,
82 => 1,
92 => 1,
97 => 1,
102 => 1,
104 => 1,
];

default:
return [];
}
}

/**
Expand Down