Your one-stop-cake-shop for everything Freshly Baked has to offer

fix(m): correct start/end requirements

Previously we were doctoring the regex in an interesting way that
wouldn't have worked with | (regex or). Since as ^^ still matches the
start of the string, we don't need to strip it out. Finally, to make
sure that regex or can't scupper things, we need to wrap everything in a
non-capturing group...

+2 -16
+2 -16
menu/src/regex.rs
··· 17 17 18 18 pub(crate) async fn get_redirect(go: &str) -> Option<Redirect> { 19 19 let redirect = sqlx::query!( 20 - r#"SELECT "from", "to" FROM regex WHERE $1 ~* ('^' || "from" || '$') LIMIT 1"#, 20 + r#"SELECT "from", "to" FROM regex WHERE $1 ~* ('^(?:' || "from" || ')$') LIMIT 1"#, 21 21 go.to_lowercase() 22 22 ) 23 23 .fetch_one( ··· 32 32 .await; 33 33 34 34 if let Ok(record) = redirect { 35 - let re = RegexBuilder::new(&format!("^{}$", record.from)) 35 + let re = RegexBuilder::new(&format!("^(?:{})$", record.from)) 36 36 .case_insensitive(true) 37 37 .build() 38 38 .unwrap(); ··· 87 87 Ok(link_table) 88 88 } 89 89 90 - fn trim_prefix(s: &str, prefix: char) -> &str { 91 - if s.starts_with(prefix) { &s[1..] } else { s } 92 - } 93 - 94 - fn trim_suffix(s: &str, suffix: char) -> &str { 95 - if s.starts_with(suffix) { 96 - &s[..s.len() - 1] 97 - } else { 98 - s 99 - } 100 - } 101 - 102 90 pub(crate) async fn create( 103 91 from: &str, 104 92 to: &str, ··· 106 94 current: Option<&String>, 107 95 ) -> CreationResult { 108 96 println!("Attempting to make go/{} -> {}", from, to); 109 - 110 - let from = trim_suffix(trim_prefix(from, '^'), '$'); // I think this is maybe broken with | 111 97 112 98 let create_call = sqlx::query!( 113 99 r#"