GithubActionError: escape more special chars (#10243)
parent
90087b4fb3
commit
6b62f98d3c
|
@ -36,9 +36,8 @@ final class GithubActionError
|
||||||
public function emit($message, $file = null, $line = null)
|
public function emit($message, $file = null, $line = null)
|
||||||
{
|
{
|
||||||
if (getenv('GITHUB_ACTIONS') && !getenv('COMPOSER_TESTS_ARE_RUNNING')) {
|
if (getenv('GITHUB_ACTIONS') && !getenv('COMPOSER_TESTS_ARE_RUNNING')) {
|
||||||
// newlines need to be encoded
|
$message = $this->escapeData($message);
|
||||||
// see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448
|
$file = $this->escapeProperty($file);
|
||||||
$message = str_replace("\n", '%0A', $message);
|
|
||||||
|
|
||||||
if ($file && $line) {
|
if ($file && $line) {
|
||||||
$this->io->write("::error file=". $file .",line=". $line ."::". $message);
|
$this->io->write("::error file=". $file .",line=". $line ."::". $message);
|
||||||
|
@ -49,4 +48,32 @@ final class GithubActionError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $data
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function escapeData($data) {
|
||||||
|
// see https://github.com/actions/toolkit/blob/4f7fb6513a355689f69f0849edeb369a4dc81729/packages/core/src/command.ts#L80-L85
|
||||||
|
$data = str_replace("%", '%25', $data);
|
||||||
|
$data = str_replace("\r", '%0D', $data);
|
||||||
|
$data = str_replace("\n", '%0A', $data);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $property
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function escapeProperty($property) {
|
||||||
|
// see https://github.com/actions/toolkit/blob/4f7fb6513a355689f69f0849edeb369a4dc81729/packages/core/src/command.ts#L87-L94
|
||||||
|
$property = str_replace("%", '%25', $property);
|
||||||
|
$property = str_replace("\r", '%0D', $property);
|
||||||
|
$property = str_replace("\n", '%0A', $property);
|
||||||
|
$property = str_replace(":", '%3A', $property);
|
||||||
|
$property = str_replace(",", '%2C', $property);
|
||||||
|
|
||||||
|
return $property;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue