File tree 1 file changed +17
-9
lines changed 1 file changed +17
-9
lines changed Original file line number Diff line number Diff line change 46
46
$ idleTimeout = true ;
47
47
}
48
48
49
- if (checkForFilePath ($ output )) {
50
- $ output = "CLI output suppressed, filepath detected in output. " ;
51
- }
52
-
53
49
$ exitCode = $ process ->getExitCode ();
54
50
55
51
if ($ process ->isSuccessful () || $ idleTimeout ) {
56
52
http_response_code (202 );
57
53
} else {
58
54
http_response_code (500 );
59
55
}
60
- echo $ output ;
56
+
57
+ // Suppress file paths from output
58
+ echo suppressFilePaths ($ output );
61
59
} else {
62
60
http_response_code (403 );
63
61
echo "Given command not found valid in Magento CLI Command list. " ;
@@ -115,11 +113,21 @@ function trimAfterWhitespace($string)
115
113
}
116
114
117
115
/**
118
- * Detects file path in string.
116
+ * Suppress file paths in string.
119
117
* @param string $string
120
- * @return boolean
118
+ * @return string
121
119
*/
122
- function checkForFilePath ( $ string )
120
+ function suppressFilePaths ( string $ string ): string
123
121
{
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 ;
125
133
}
You can’t perform that action at this time.
0 commit comments