Skip to content

Commit ef5dc0e

Browse files
authored
refactored escaping logic. added filename escaping. (#81)
Co-authored-by: staabm <staabm@users.noreply.github.com>
1 parent 602b57b commit ef5dc0e

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

cs2pr

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,8 @@ exit($exit);
122122
*/
123123
function annotateCheck($type, $filename, $line, $message, $colorize)
124124
{
125-
// newlines need to be encoded
126-
// see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448
127-
$message = str_replace("%", '%25', $message);
128-
$message = str_replace("\r", '%0D', $message);
129-
$message = str_replace("\n", '%0A', $message);
125+
$message = escapeData($message);
126+
$filename = escapeProperty($filename);
130127

131128
if ($colorize) {
132129
echo "\033[".($type==='error' ? '91' : '93')."m\n";
@@ -153,3 +150,33 @@ function annotateType($type, $noticeAsWarning)
153150
}
154151
return 'warning';
155152
}
153+
154+
/**
155+
* @param string $data
156+
* @return string
157+
*/
158+
function escapeData($data)
159+
{
160+
// see https://github.com/actions/toolkit/blob/4f7fb6513a355689f69f0849edeb369a4dc81729/packages/core/src/command.ts#L80-L85
161+
$data = str_replace("%", '%25', $data);
162+
$data = str_replace("\r", '%0D', $data);
163+
$data = str_replace("\n", '%0A', $data);
164+
165+
return $data;
166+
}
167+
168+
/**
169+
* @param string $property
170+
* @return string
171+
*/
172+
function escapeProperty($property)
173+
{
174+
// see https://github.com/actions/toolkit/blob/4f7fb6513a355689f69f0849edeb369a4dc81729/packages/core/src/command.ts#L87-L94
175+
$property = str_replace("%", '%25', $property);
176+
$property = str_replace("\r", '%0D', $property);
177+
$property = str_replace("\n", '%0A', $property);
178+
$property = str_replace(":", '%3A', $property);
179+
$property = str_replace(",", '%2C', $property);
180+
181+
return $property;
182+
}

0 commit comments

Comments
 (0)