diff options
| author | Lorenz Leitner <lrnz.ltnr@gmail.com> | 2021-10-14 19:16:16 +0200 |
|---|---|---|
| committer | Lorenz Leitner <lrnz.ltnr@gmail.com> | 2021-10-14 19:16:16 +0200 |
| commit | b5f3a548388931c3245473b61f6ea4b96341a1a6 (patch) | |
| tree | 8383f4e9728f1cada57ece9efa384f2adb02f2b4 /src/util | |
| parent | ci: remove restriction from tanka include (diff) | |
Fix URL shortening of some WA inputs
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/web.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util/web.rs b/src/util/web.rs index 77e20a3..bfa7003 100644 --- a/src/util/web.rs +++ b/src/util/web.rs @@ -1,5 +1,10 @@ use anyhow::{Context, Error, Result}; use reqwest::{get, Url}; +use urlparse::quote_plus as urlparse_quote_plus; + +pub(crate) fn quote_plus(text: &str) -> Result<String, Error> { + Ok(urlparse_quote_plus(text, b"")?) +} // TODO: Either catinator should have a URL shortening utility module, // or we should start our own service @@ -18,3 +23,27 @@ pub(crate) async fn shorten_url(url: &str) -> Result<String, Error> { Ok(short_url) } + +#[cfg(test)] +mod tests { + use super::{quote_plus}; + use anyhow::{Error, Result}; + + #[test] + fn test_quote_plus_1() -> Result<(), Error> { + assert_eq!(quote_plus("5/10")?, "5%2F10"); + Ok(()) + } + + #[test] + fn test_quote_plus_2() -> Result<(), Error> { + assert_eq!(quote_plus("1 * 2")?, "1+%2A+2"); + Ok(()) + } + + #[test] + fn test_quote_plus_3() -> Result<(), Error> { + assert_eq!(quote_plus("e_plus("1 * 2")?)?, "1%2B%252A%2B2"); + Ok(()) + } +} |
