Skip to content

Commit

Permalink
escape special characters in regex of service names
Browse files Browse the repository at this point in the history
  • Loading branch information
cvkem committed Dec 4, 2023
1 parent cc04192 commit 49b130d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/stitch/api/mermaid/diagram.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::service_oper_graph::{LinkType, Position, ServiceOperGraph, ServiceOperationType};
use crate::{stats::CChainStatsKey, Stitched};
use regex::Regex;
use regex::{self, Regex};
use std::collections::HashMap;

struct CountedPrefix(HashMap<String, f64>);
Expand Down Expand Up @@ -34,9 +34,10 @@ fn split_service(service_oper: &str) -> &str {
/// 1. find all paths in 'data' that touch 'service_oper' and construct the graph including the counts (statistics). In this stage we also collect that paths leading to 'service_oper'
/// 2. The (deduplicated) set of all paths leading into 'service_oper' are used to construct all the upstream process-steps. However, we do not have count-statistics for these paths
fn build_serv_oper_graph(data: &Stitched, service_oper: &str) -> ServiceOperGraph {
let esc_service_oper = regex::escape(service_oper);
let re_service_oper =
Regex::new(service_oper).expect("Failed to create regex for service_oper");
let re_so_prefix = Regex::new(&format!("^.*{}", service_oper))
Regex::new(&esc_service_oper).expect("Failed to create regex for service_oper");
let re_so_prefix = Regex::new(&format!("^.*{}", esc_service_oper))
.expect("Failed to create regex for service_oper_prefix");
let service = split_service(service_oper);

Expand Down
5 changes: 3 additions & 2 deletions src/stitch/api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{
};
use crate::{BestFit, Stitched, StitchedLine, StitchedSet};
use log::error;
use regex::Regex;
use regex::{self, Regex};
use std::cmp::Ordering;

const DEFAULT_RANK: f64 = -1.0; // indicates growth not defined
Expand Down Expand Up @@ -199,7 +199,8 @@ fn get_call_chain_list_end2end(
all_chains: bool,
inbound_idx_filter: Option<i64>,
) -> ProcessList {
let re_proc_oper = Regex::new(proc_oper).expect("Failed to create regex for proc_oper");
let esc_proc_oper = regex::escape(proc_oper);
let re_proc_oper = Regex::new(&esc_proc_oper).expect("Failed to create regex for proc_oper");

let inbound_prefix_idx = InboundPrefixIdx::new(data, proc_oper);

Expand Down

0 comments on commit 49b130d

Please sign in to comment.