Skip to content

Commit a95569c

Browse files
committed
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.
1 parent 0d79723 commit a95569c

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

src/Files/File.php

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -967,59 +967,63 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
967967

968968
// Make sure we are not ignoring this file.
969969
$included = null;
970-
foreach ($checkCodes as $checkCode) {
971-
$patterns = null;
972-
973-
if (isset($this->configCache['includePatterns'][$checkCode]) === true) {
974-
$patterns = $this->configCache['includePatterns'][$checkCode];
975-
$excluding = false;
976-
} else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) {
977-
$patterns = $this->configCache['ignorePatterns'][$checkCode];
978-
$excluding = true;
979-
}
980-
981-
if ($patterns === null) {
982-
continue;
983-
}
984-
985-
foreach ($patterns as $pattern => $type) {
986-
// While there is support for a type of each pattern
987-
// (absolute or relative) we don't actually support it here.
988-
$replacements = [
989-
'\\,' => ',',
990-
'*' => '.*',
991-
];
992-
993-
// We assume a / directory separator, as do the exclude rules
994-
// most developers write, so we need a special case for any system
995-
// that is different.
996-
if (DIRECTORY_SEPARATOR === '\\') {
997-
$replacements['/'] = '\\\\';
970+
if (trim($this->path, '\'"') === 'STDIN') {
971+
$included = true;
972+
} else {
973+
foreach ($checkCodes as $checkCode) {
974+
$patterns = null;
975+
976+
if (isset($this->configCache['includePatterns'][$checkCode]) === true) {
977+
$patterns = $this->configCache['includePatterns'][$checkCode];
978+
$excluding = false;
979+
} else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) {
980+
$patterns = $this->configCache['ignorePatterns'][$checkCode];
981+
$excluding = true;
998982
}
999983

1000-
$pattern = '`'.strtr($pattern, $replacements).'`i';
1001-
$matched = preg_match($pattern, $this->path);
984+
if ($patterns === null) {
985+
continue;
986+
}
1002987

1003-
if ($matched === 0) {
1004-
if ($excluding === false && $included === null) {
1005-
// This file path is not being included.
1006-
$included = false;
988+
foreach ($patterns as $pattern => $type) {
989+
// While there is support for a type of each pattern
990+
// (absolute or relative) we don't actually support it here.
991+
$replacements = [
992+
'\\,' => ',',
993+
'*' => '.*',
994+
];
995+
996+
// We assume a / directory separator, as do the exclude rules
997+
// most developers write, so we need a special case for any system
998+
// that is different.
999+
if (DIRECTORY_SEPARATOR === '\\') {
1000+
$replacements['/'] = '\\\\';
10071001
}
10081002

1009-
continue;
1010-
}
1003+
$pattern = '`'.strtr($pattern, $replacements).'`i';
1004+
$matched = preg_match($pattern, $this->path);
10111005

1012-
if ($excluding === true) {
1013-
// This file path is being excluded.
1014-
$this->ignoredCodes[$checkCode] = true;
1015-
return false;
1016-
}
1006+
if ($matched === 0) {
1007+
if ($excluding === false && $included === null) {
1008+
// This file path is not being included.
1009+
$included = false;
1010+
}
10171011

1018-
// This file path is being included.
1019-
$included = true;
1020-
break;
1012+
continue;
1013+
}
1014+
1015+
if ($excluding === true) {
1016+
// This file path is being excluded.
1017+
$this->ignoredCodes[$checkCode] = true;
1018+
return false;
1019+
}
1020+
1021+
// This file path is being included.
1022+
$included = true;
1023+
break;
1024+
}//end foreach
10211025
}//end foreach
1022-
}//end foreach
1026+
}//end if
10231027

10241028
if ($included === false) {
10251029
// There were include rules set, but this file

0 commit comments

Comments
 (0)