diff options
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(()) + } +} |
