Skip to content

Commit

Permalink
fix(message): fixed porcessing of removing newline character #1145
Browse files Browse the repository at this point in the history
  • Loading branch information
hitenkoku committed Sep 3, 2023
1 parent 0266489 commit 4d208b0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/detections/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn insert(
let mut record_details_info_map = HashMap::new();
if !is_agg {
//ここの段階でdetailsの内容でaliasを置き換えた内容と各種、key,valueの組み合わせのmapを取得する
let (mut removed_sp_parsed_detail, details_in_record) = parse_message(
let (removed_sp_parsed_detail, details_in_record) = parse_message(
event_record,
output,
eventkey_alias,
Expand All @@ -136,34 +136,33 @@ pub fn insert(
field_data_map,
);

let removed_sp_char = |mut cs: CompactString| -> CompactString {
let removed_sp_char = |cs: CompactString| -> CompactString {
let mut newline_replaced_cs = cs
.replace('\n', "🛂n")
.replace('\r', "🛂r")
.replace('\t', "🛂t");
let mut prev = 'a';
cs.retain(|ch| {
newline_replaced_cs.retain(|ch| {
let retain_flag = (prev == ' ' && ch == ' ') || ch.is_control();
if !retain_flag {
prev = ch;
}
!retain_flag
});
cs.clone()
newline_replaced_cs.into()
};
let mut sp_removed_details_in_record = vec![];
details_in_record.iter().for_each(|v| {
sp_removed_details_in_record.push(removed_sp_char(v.clone()));
});
record_details_info_map.insert("#Details".into(), sp_removed_details_in_record);
// 特殊文字の除外のためのretain処理
removed_sp_parsed_detail = removed_sp_char(removed_sp_parsed_detail);

// Details内にある改行文字は除外しないために絵文字を含めた特殊な文字に変換することで対応する
let parsed_detail = removed_sp_parsed_detail
.replace('\n', "🛂n")
.replace('\r', "🛂r")
.replace('\t', "🛂t");
let parsed_detail = removed_sp_char(removed_sp_parsed_detail);
detect_info.detail = if parsed_detail.is_empty() {
CompactString::from("-")
} else {
parsed_detail.into()
parsed_detail
};
}
let mut replaced_profiles: Vec<(CompactString, Profile)> = vec![];
Expand Down

0 comments on commit 4d208b0

Please sign in to comment.