Skip to content

Commit

Permalink
Don't flag unset()'s in input sanitization sniff
Browse files Browse the repository at this point in the history
Fixes #187
  • Loading branch information
JDGrimes committed Jun 26, 2014
1 parent aa044c2 commit 64fab4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Sniffs/VIP/ValidatedSanitizedInputSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )

// Ignore if wrapped inside ISSET
end( $nested ); // Get closest parenthesis
if ( in_array( $tokens[ key( $nested ) - 1 ]['code'], array( T_ISSET, T_EMPTY ) ) )
if ( in_array( $tokens[ key( $nested ) - 1 ]['code'], array( T_ISSET, T_EMPTY, T_UNSET ) ) )
return;

$varKey = $this->getArrayIndexKey( $phpcsFile, $tokens, $stackPtr );
Expand Down Expand Up @@ -107,7 +107,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
}

for ( $i = $scope_start + 1; $i < $scope_end; $i++ ) {
if ( ! in_array( $tokens[$i]['code'], array( T_ISSET, T_EMPTY ) ) ) {
if ( ! in_array( $tokens[$i]['code'], array( T_ISSET, T_EMPTY, T_UNSET ) ) ) {
continue;
}
$issetPtr = $i;
Expand Down Expand Up @@ -148,6 +148,8 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
) {
$is_sanitized = true;
}
} elseif ( T_UNSET === $function['code'] ) {
$is_sanitized = true;
}

if ( ! $is_sanitized ) {
Expand Down
2 changes: 2 additions & 0 deletions Tests/VIP/ValidatedSanitizedInputUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ $values = array_values( $_POST );
foreach( $_POST as $key => $value ) {
// ..
}

unset( $_GET['test'] ) // ok

0 comments on commit 64fab4f

Please sign in to comment.