Skip to content

Commit

Permalink
Make escaping on-par with the one found in actions/toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Dec 6, 2024
1 parent 5e7e2e9 commit 9c07970
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/ameba/formatter/github_actions_formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Ameba::Formatter
output << command_name(issue.rule.severity)
output << " "
output << "file="
output << source.path
output << escape_property(source.path)
if location = issue.location
output << ",line="
output << location.line_number
Expand All @@ -29,10 +29,9 @@ module Ameba::Formatter
output << end_location.column_number
end
output << ",title="
output << issue.rule.name
output << escape_property(issue.rule.name)
output << "::"
# https://github.com/actions/toolkit/issues/193
output << issue.message.gsub('\n', "%0A")
output << escape_data(issue.message)
output << "\n"
end
end
Expand All @@ -45,5 +44,26 @@ module Ameba::Formatter
in .convention? then "notice"
end
end

# See for details:
# - https://github.com/actions/toolkit/blob/74906bea83a0dbf6aaba2d00b732deb0c3aefd2d/packages/core/src/command.ts#L92-L97
# - https://github.com/actions/toolkit/issues/193
private def escape_data(string : String) : String
string
.gsub('%', "%25")
.gsub('\r', "%0D")
.gsub('\n', "%0A")
end

# See for details:
# - https://github.com/actions/toolkit/blob/74906bea83a0dbf6aaba2d00b732deb0c3aefd2d/packages/core/src/command.ts#L99-L106
private def escape_property(string : String) : String
string
.gsub('%', "%25")
.gsub('\r', "%0D")
.gsub('\n', "%0A")
.gsub(':', "%3A")
.gsub(',', "%2C")
end
end
end

0 comments on commit 9c07970

Please sign in to comment.