From b73bf3e0238c3743efb5f15f05e8d78658a49cbd Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 1 Nov 2021 12:15:03 +0100 Subject: [PATCH 1/6] refactored escaping logic. added filename escaping. --- cs2pr | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/cs2pr b/cs2pr index e0aab70..159c3b2 100755 --- a/cs2pr +++ b/cs2pr @@ -122,11 +122,8 @@ exit($exit); */ function annotateCheck($type, $filename, $line, $message, $colorize) { - // newlines need to be encoded - // see https://github.com/actions/starter-workflows/issues/68#issuecomment-581479448 - $message = str_replace("%", '%25', $message); - $message = str_replace("\r", '%0D', $message); - $message = str_replace("\n", '%0A', $message); + $message = escapeData($message); + $filename = escapeProperty($filename); if ($colorize) { echo "\033[".($type==='error' ? '91' : '93')."m\n"; @@ -153,3 +150,24 @@ function annotateType($type, $noticeAsWarning) } return 'warning'; } + +function escapeData(string $data):string { + // 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; +} + +function escapeProperty(string $property):string { + // 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; +} + From 10d8d09cf1db044d6b68a83fc29379983a8b64e3 Mon Sep 17 00:00:00 2001 From: staabm Date: Mon, 1 Nov 2021 11:15:53 +0000 Subject: [PATCH 2/6] Apply php-cs-fixer changes --- cs2pr | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cs2pr b/cs2pr index 159c3b2..991dbbc 100755 --- a/cs2pr +++ b/cs2pr @@ -151,7 +151,8 @@ function annotateType($type, $noticeAsWarning) return 'warning'; } -function escapeData(string $data):string { +function escapeData(string $data):string +{ // 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); @@ -160,7 +161,8 @@ function escapeData(string $data):string { return $data; } -function escapeProperty(string $property):string { +function escapeProperty(string $property):string +{ // 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); @@ -170,4 +172,3 @@ function escapeProperty(string $property):string { return $property; } - From 8eba11a09c7dde3e2b8a2681e843d990a24c0533 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 1 Nov 2021 12:17:24 +0100 Subject: [PATCH 3/6] Update cs2pr --- cs2pr | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/cs2pr b/cs2pr index 991dbbc..7533f01 100755 --- a/cs2pr +++ b/cs2pr @@ -151,24 +151,30 @@ function annotateType($type, $noticeAsWarning) return 'warning'; } -function escapeData(string $data):string -{ - // 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 $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; + } -function escapeProperty(string $property):string -{ - // 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; -} + /** + * @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; + } From 23243fd6302b6da85ea8f4cc64ffcc1665364123 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 1 Nov 2021 12:19:03 +0100 Subject: [PATCH 4/6] Update cs2pr --- cs2pr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cs2pr b/cs2pr index 7533f01..ba01a96 100755 --- a/cs2pr +++ b/cs2pr @@ -155,7 +155,7 @@ function annotateType($type, $noticeAsWarning) * @param string $data * @return string */ - private function escapeData($data) { + 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); @@ -168,7 +168,7 @@ function annotateType($type, $noticeAsWarning) * @param string $property * @return string */ - private function escapeProperty($property) { + 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); From 5f7cb6e9955554915d2e6df37a76c40b62e36f6e Mon Sep 17 00:00:00 2001 From: staabm Date: Mon, 1 Nov 2021 11:19:53 +0000 Subject: [PATCH 5/6] Apply php-cs-fixer changes --- cs2pr | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cs2pr b/cs2pr index ba01a96..ab0ab24 100755 --- a/cs2pr +++ b/cs2pr @@ -155,7 +155,8 @@ function annotateType($type, $noticeAsWarning) * @param string $data * @return string */ - function escapeData($data) { + 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); @@ -168,7 +169,8 @@ function annotateType($type, $noticeAsWarning) * @param string $property * @return string */ - function escapeProperty($property) { + 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); From 4edf24c1ca2c7b2f5c4cb637ae78e2334201f665 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 1 Nov 2021 12:20:48 +0100 Subject: [PATCH 6/6] Update cs2pr --- cs2pr | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/cs2pr b/cs2pr index ab0ab24..69e611b 100755 --- a/cs2pr +++ b/cs2pr @@ -151,32 +151,32 @@ function annotateType($type, $noticeAsWarning) return 'warning'; } - /** - * @param string $data - * @return string - */ - 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 $data + * @return string + */ +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); - /** - * @param string $property - * @return string - */ - 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; - } + return $data; +} + +/** + * @param string $property + * @return string + */ +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; +}