From 0d79723446243f12cb575bbfbc680a0d658f3390 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 8 Sep 2020 02:49:05 +0200 Subject: [PATCH 1/2] File::process(): don't apply include/exclude patterns to STDIN Note: using `trim()` to remove potential quotes around `STDIN` which are sometimes passed by IDEs. --- src/Files/File.php | 62 ++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/Files/File.php b/src/Files/File.php index b7e35488f0..27b10a3b11 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -442,30 +442,11 @@ public function process() continue; } - // If the file path matches one of our ignore patterns, skip it. - // While there is support for a type of each pattern - // (absolute or relative) we don't actually support it here. - foreach ($listenerData['ignore'] as $pattern) { - // We assume a / directory separator, as do the exclude rules - // most developers write, so we need a special case for any system - // that is different. - if (DIRECTORY_SEPARATOR === '\\') { - $pattern = str_replace('/', '\\\\', $pattern); - } - - $pattern = '`'.$pattern.'`i'; - if (preg_match($pattern, $this->path) === 1) { - $this->ignoredListeners[$class] = true; - continue(2); - } - } - - // If the file path does not match one of our include patterns, skip it. - // While there is support for a type of each pattern - // (absolute or relative) we don't actually support it here. - if (empty($listenerData['include']) === false) { - $included = false; - foreach ($listenerData['include'] as $pattern) { + if (trim($this->path, '\'"') !== 'STDIN') { + // If the file path matches one of our ignore patterns, skip it. + // While there is support for a type of each pattern + // (absolute or relative) we don't actually support it here. + foreach ($listenerData['ignore'] as $pattern) { // We assume a / directory separator, as do the exclude rules // most developers write, so we need a special case for any system // that is different. @@ -475,15 +456,36 @@ public function process() $pattern = '`'.$pattern.'`i'; if (preg_match($pattern, $this->path) === 1) { - $included = true; - break; + $this->ignoredListeners[$class] = true; + continue(2); } } - if ($included === false) { - $this->ignoredListeners[$class] = true; - continue; - } + // If the file path does not match one of our include patterns, skip it. + // While there is support for a type of each pattern + // (absolute or relative) we don't actually support it here. + if (empty($listenerData['include']) === false) { + $included = false; + foreach ($listenerData['include'] as $pattern) { + // We assume a / directory separator, as do the exclude rules + // most developers write, so we need a special case for any system + // that is different. + if (DIRECTORY_SEPARATOR === '\\') { + $pattern = str_replace('/', '\\\\', $pattern); + } + + $pattern = '`'.$pattern.'`i'; + if (preg_match($pattern, $this->path) === 1) { + $included = true; + break; + } + } + + if ($included === false) { + $this->ignoredListeners[$class] = true; + continue; + } + }//end if }//end if $this->activeListener = $class; From a95569ca6077ecc1529681df3681627e2034a5a4 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 8 Sep 2020 02:49:57 +0200 Subject: [PATCH 2/2] File::addMessage(): don't apply include/exclude patterns to STDIN Note: using `trim()` to remove potential quotes around `STDIN` which are sometimes passed by IDEs. --- src/Files/File.php | 94 ++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/src/Files/File.php b/src/Files/File.php index 27b10a3b11..efb5d22370 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -967,59 +967,63 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s // Make sure we are not ignoring this file. $included = null; - foreach ($checkCodes as $checkCode) { - $patterns = null; - - if (isset($this->configCache['includePatterns'][$checkCode]) === true) { - $patterns = $this->configCache['includePatterns'][$checkCode]; - $excluding = false; - } else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) { - $patterns = $this->configCache['ignorePatterns'][$checkCode]; - $excluding = true; - } - - if ($patterns === null) { - continue; - } - - foreach ($patterns as $pattern => $type) { - // While there is support for a type of each pattern - // (absolute or relative) we don't actually support it here. - $replacements = [ - '\\,' => ',', - '*' => '.*', - ]; - - // We assume a / directory separator, as do the exclude rules - // most developers write, so we need a special case for any system - // that is different. - if (DIRECTORY_SEPARATOR === '\\') { - $replacements['/'] = '\\\\'; + if (trim($this->path, '\'"') === 'STDIN') { + $included = true; + } else { + foreach ($checkCodes as $checkCode) { + $patterns = null; + + if (isset($this->configCache['includePatterns'][$checkCode]) === true) { + $patterns = $this->configCache['includePatterns'][$checkCode]; + $excluding = false; + } else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) { + $patterns = $this->configCache['ignorePatterns'][$checkCode]; + $excluding = true; } - $pattern = '`'.strtr($pattern, $replacements).'`i'; - $matched = preg_match($pattern, $this->path); + if ($patterns === null) { + continue; + } - if ($matched === 0) { - if ($excluding === false && $included === null) { - // This file path is not being included. - $included = false; + foreach ($patterns as $pattern => $type) { + // While there is support for a type of each pattern + // (absolute or relative) we don't actually support it here. + $replacements = [ + '\\,' => ',', + '*' => '.*', + ]; + + // We assume a / directory separator, as do the exclude rules + // most developers write, so we need a special case for any system + // that is different. + if (DIRECTORY_SEPARATOR === '\\') { + $replacements['/'] = '\\\\'; } - continue; - } + $pattern = '`'.strtr($pattern, $replacements).'`i'; + $matched = preg_match($pattern, $this->path); - if ($excluding === true) { - // This file path is being excluded. - $this->ignoredCodes[$checkCode] = true; - return false; - } + if ($matched === 0) { + if ($excluding === false && $included === null) { + // This file path is not being included. + $included = false; + } - // This file path is being included. - $included = true; - break; + continue; + } + + if ($excluding === true) { + // This file path is being excluded. + $this->ignoredCodes[$checkCode] = true; + return false; + } + + // This file path is being included. + $included = true; + break; + }//end foreach }//end foreach - }//end foreach + }//end if if ($included === false) { // There were include rules set, but this file