Skip to content

Commit 0654ac6

Browse files
authored
Merge pull request #354 from magento-commerce/ACQE-5855
ACQE-5855: Change command <magentoCLI> to maintain CLI output and onl…
2 parents d273cc2 + 803d4eb commit 0654ac6

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

etc/config/command.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@
4646
$idleTimeout = true;
4747
}
4848

49-
if (checkForFilePath($output)) {
50-
$output = "CLI output suppressed, filepath detected in output.";
51-
}
52-
5349
$exitCode = $process->getExitCode();
5450

5551
if ($process->isSuccessful() || $idleTimeout) {
5652
http_response_code(202);
5753
} else {
5854
http_response_code(500);
5955
}
60-
echo $output;
56+
57+
// Suppress file paths from output
58+
echo suppressFilePaths($output);
6159
} else {
6260
http_response_code(403);
6361
echo "Given command not found valid in Magento CLI Command list.";
@@ -115,11 +113,21 @@ function trimAfterWhitespace($string)
115113
}
116114

117115
/**
118-
* Detects file path in string.
116+
* Suppress file paths in string.
119117
* @param string $string
120-
* @return boolean
118+
* @return string
121119
*/
122-
function checkForFilePath($string)
120+
function suppressFilePaths(string $string): string
123121
{
124-
return preg_match('/\/[\S]+\//', $string);
122+
// Match file paths on both *nix and Windows system
123+
$filePathPattern = '~(?:[A-Za-z]:[\\\/]|\\\\|\/)\S+~';
124+
$replacement = '[suppressed_path]';
125+
126+
preg_match_all($filePathPattern, $string, $matches);
127+
if (!empty($matches)) {
128+
foreach ($matches[0] as $match) {
129+
$string = str_replace($match, $replacement, $string);
130+
}
131+
}
132+
return $string;
125133
}

0 commit comments

Comments
 (0)