Skip to content

Commit

Permalink
[skip ci] yolo
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Mar 24, 2024
1 parent 6f1535c commit ebf27aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions crates/core/src/pattern/includes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ impl Matcher for Includes {
logs: &mut AnalysisLogs,
) -> Result<bool> {
match &self.includes {
Pattern::Regex(_) => {
Ok(true)
// bail!("regex patterns are not allowed in includes")
Pattern::Regex(pattern) => {
pattern.execute_matching(binding, state, context, logs, false)
}
Pattern::ASTNode(_)
| Pattern::List(_)
Expand Down
12 changes: 7 additions & 5 deletions crates/core/src/pattern/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ impl RegexPattern {
.strip_suffix('\"')
.ok_or_else(|| anyhow!("invalid regex postfix"))?;

let regex = format!("^{}$", regex);

RegexLike::Regex(Regex::new(regex.as_str())?)
RegexLike::Regex(Regex::new(regex)?)
} else {
let back_tick_node = regex_node
.child_by_field_name("snippet")
Expand Down Expand Up @@ -136,13 +134,13 @@ impl RegexPattern {
))))
}

fn execute_matching<'a>(
pub(crate) fn execute_matching<'a>(
&'a self,
binding: &ResolvedPattern<'a>,
state: &mut State<'a>,
context: &Context<'a>,
logs: &mut AnalysisLogs,
entire_string: bool,
must_match_entire_string: bool,
) -> Result<bool> {
let text = binding.text(&state.files)?;
let resolved_regex = match self.regex {
Expand All @@ -153,6 +151,10 @@ impl RegexPattern {
Regex::new(&text)?
}
};
let wrapped_regex = match must_match_entire_string {
true => format!("^{}$", resolved_regex),
false => format!("{}", resolved_regex),
};
let captures = match resolved_regex.captures(&text) {
Some(captures) => captures,
None => return Ok(false),
Expand Down

0 comments on commit ebf27aa

Please sign in to comment.