From 345f95b1ff5f2d244cf8d4591509290b27eaa248 Mon Sep 17 00:00:00 2001 From: "Aviv \"RustyStriker\" Romem" Date: Sat, 11 Jun 2022 13:31:28 +0300 Subject: [PATCH] fixed stupid bug --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index a15a60e..d634a1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,6 +141,7 @@ fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str, cfile else if s.contains(tag) { // We have the first tag but not the second, so we want to go back in the input file.. let (copy, keep) = s.split_once(tag).unwrap(); + println!("Contains only tag\npre {}\n post {}", copy, keep); out.write(copy.as_bytes()).unwrap(); // Return the length of whatever we just read and the tag length @@ -148,14 +149,13 @@ fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str, cfile } else { // Make sure we are not just cutting it in the middle - let chars = tag.chars().collect::>(); let mut wrote = false; - for i in 1..chars.len() { - if s.ends_with(&chars[..i]) { - let back: usize = chars[..i].iter().map(|x| x.len_utf8()).sum(); - let to_write = s.replace(&chars[..i], ""); + for i in 1..tag.chars().count() { + let slice = tag.get(..i).unwrap(); + if s.ends_with(slice) { + let back: usize = slice.len(); + let to_write = s.replace(slice, ""); out.write(to_write.as_bytes()).unwrap(); - inp.seek(SeekFrom::Current(-1 * back as i64)).unwrap(); wrote = true; break;