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

fix(m): correct start/end requirements #193

closed opened by a.starrysky.fyi targeting main from private/minion/push-rvvlvvqouvzu

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...

Labels

None yet.

requested-reviewers

None yet.

approved

None yet.

tested-working

None yet.

rejected

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:uuyqs6y3pwtbteet4swt5i5y/sh.tangled.repo.pull/3mdjm43jtd322
+2 -16
Diff #0
+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, ··· 107 95 ) -> CreationResult { 108 96 println!("Attempting to make go/{} -> {}", from, to); 109 97 110 - let from = trim_suffix(trim_prefix(from, '^'), '$'); // I think this is maybe broken with | 111 - 112 98 let create_call = sqlx::query!( 113 99 r#" 114 100 WITH insertion AS (

History

1 round 0 comments
sign up or login to add to the discussion
a.starrysky.fyi submitted #0
1 commit
expand
fix(m): correct start/end requirements
1/5 failed, 4/5 success
expand
expand 0 comments
closed without merging