Skip to content

Commit

Permalink
feat(utils):removed trailing comma from field #386
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenkoku committed Jan 23, 2023
1 parent 5b42fe9 commit 5a21f90
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/detections/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ pub fn str_time_to_datetime(system_time_str: &str) -> Option<DateTime<Utc>> {
/// serde:Valueの型を確認し、文字列を返します。
pub fn get_serde_number_to_string(value: &serde_json::Value) -> Option<String> {
if value.is_string() {
Option::Some(value.as_str().unwrap_or("").to_string())
let val_str = value.as_str().unwrap_or("");
if val_str.ends_with(",") {
Option::Some(val_str[..val_str.len() - 1].to_string())
} else {
Option::Some(val_str.to_string())
}
} else if value.is_object() || value.is_null() {
// Object type is not specified record value.
Option::None
Expand Down Expand Up @@ -342,7 +347,13 @@ pub fn create_recordinfos(record: &Value) -> String {

output_vec
.iter()
.map(|(key, value)| format!("{}: {}", key, value))
.map(|(key, value)| {
if value.ends_with(",") {
format!("{}: {}", key, &value[..value.len() - 1])
} else {
format!("{}: {}", key, value)
}
})
.join(" ¦ ")
}

Expand Down

0 comments on commit 5a21f90

Please sign in to comment.