Skip to content

Commit

Permalink
rule-parser: fix stripping of quotes
Browse files Browse the repository at this point in the history
Re-add '\' when found to not be escaping a double quote.

GitHub issue:
#177
  • Loading branch information
jasonish committed Jun 8, 2021
1 parent de3bdc2 commit 0b63979
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions suricata-rule-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,21 @@ fn strip_quotes(input: &str) -> String {
let mut out: Vec<char> = Vec::new();

for c in input.chars() {
if escaped {
out.push(c);
escaped = false;
} else {
match c {
'"' => {}
'\\' => {
escaped = true;
}
_ => {
out.push(c);
match c {
'"' if escaped => {
out.push(c);
escaped = false;
}
'"' => {}
'\\' => {
escaped = true;
}
_ => {
if escaped {
out.push('\\');
escaped = false;
}
out.push(c);
}
}
}
Expand Down Expand Up @@ -436,6 +439,17 @@ mod tests {
}
))
);

assert_eq!(
parse_option(r#"pcre:"/^/index\.html/$/U";"#),
Ok((
"",
RuleOption {
key: String::from("pcre"),
val: Some(r#"/^/index\.html/$/U"#.to_string()),
}
))
);
}

#[test]
Expand Down

0 comments on commit 0b63979

Please sign in to comment.