aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-03-14 04:50:54 +0100
committerJokler <jokler.contact@gmail.com>2018-03-14 04:50:54 +0100
commitbadc615a92a3778778c2f14ce8bcc951313b5d9f (patch)
treed14f0796cfd3cd16324b6c5e3f74e345f8d23035 /src
parent723adb13e4e9701f6b79bd10868a53ad8babfe8f (diff)
downloadfrippy-badc615a92a3778778c2f14ce8bcc951313b5d9f.tar.gz
frippy-badc615a92a3778778c2f14ce8bcc951313b5d9f.zip
Fix escaped backslashes in sed strings
Diffstat (limited to 'src')
-rw-r--r--src/plugins/sed.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/plugins/sed.rs b/src/plugins/sed.rs
index 6f3d0bd..e583811 100644
--- a/src/plugins/sed.rs
+++ b/src/plugins/sed.rs
@@ -48,6 +48,23 @@ impl Sed {
messages.push(message);
}
+ fn format_escaped(&self, input: &str) -> String {
+ let mut output = String::with_capacity(input.len());
+ let mut escape = false;
+
+ for c in input.chars() {
+ if !escape && c == '\\' {
+ escape = true;
+ continue;
+ }
+ escape = false;
+
+ output.push(c);
+ }
+
+ output
+ }
+
fn run_regex(&self, channel: &str, message: &str) -> Result<String, SedError> {
let mut global_match = false;
let mut case_insens = false;
@@ -58,8 +75,8 @@ impl Sed {
let captures = RE.captures(message).unwrap();
debug!("{:?}", captures);
- let first = captures.get(1).unwrap().as_str().replace(r"\/", "/");
- let second = captures.get(2).unwrap().as_str().replace(r"\/", "/");
+ let first = self.format_escaped(captures.get(1).unwrap().as_str());
+ let second = self.format_escaped(captures.get(2).unwrap().as_str());
if let Some(flags) = captures.get(3) {
let flags = flags.as_str();