mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(diagnostics): need to escape strings for --format github
closes #3212
This commit is contained in:
parent
d8173e1000
commit
b86ef7d2dd
1 changed files with 36 additions and 0 deletions
|
|
@ -38,5 +38,41 @@ fn format_github(diagnostic: &Error) -> String {
|
|||
Severity::Warning | miette::Severity::Advice => "warning",
|
||||
};
|
||||
let title = rule_id.map_or(Cow::Borrowed("oxlint"), Cow::Owned);
|
||||
let filename = escape_property(&filename);
|
||||
let message = escape_data(&message);
|
||||
format!("::{severity} file={filename},line={line},endLine={line},col={column},endColumn={column},title={title}::{message}\n")
|
||||
}
|
||||
|
||||
fn escape_data(value: &str) -> String {
|
||||
// Refs:
|
||||
// - https://github.com/actions/runner/blob/a4c57f27477077e57545af79851551ff7f5632bd/src/Runner.Common/ActionCommand.cs#L18-L22
|
||||
// - https://github.com/actions/toolkit/blob/fe3e7ce9a7f995d29d1fcfd226a32bca407f9dc8/packages/core/src/command.ts#L80-L94
|
||||
let mut result = String::with_capacity(value.len());
|
||||
for c in value.chars() {
|
||||
match c {
|
||||
'\r' => result.push_str("%0D"),
|
||||
'\n' => result.push_str("%0A"),
|
||||
'%' => result.push_str("%25"),
|
||||
_ => result.push(c),
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn escape_property(value: &str) -> String {
|
||||
// Refs:
|
||||
// - https://github.com/actions/runner/blob/a4c57f27477077e57545af79851551ff7f5632bd/src/Runner.Common/ActionCommand.cs#L25-L32
|
||||
// - https://github.com/actions/toolkit/blob/fe3e7ce9a7f995d29d1fcfd226a32bca407f9dc8/packages/core/src/command.ts#L80-L94
|
||||
let mut result = String::with_capacity(value.len());
|
||||
for c in value.chars() {
|
||||
match c {
|
||||
'\r' => result.push_str("%0D"),
|
||||
'\n' => result.push_str("%0A"),
|
||||
':' => result.push_str("%3A"),
|
||||
',' => result.push_str("%2C"),
|
||||
'%' => result.push_str("%25"),
|
||||
_ => result.push(c),
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue