aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorLorenz Leitner <lrnz.ltnr@gmail.com>2021-10-14 19:16:16 +0200
committerLorenz Leitner <lrnz.ltnr@gmail.com>2021-10-14 19:16:16 +0200
commitb5f3a548388931c3245473b61f6ea4b96341a1a6 (patch)
tree8383f4e9728f1cada57ece9efa384f2adb02f2b4 /src/util
parentci: remove restriction from tanka include (diff)
Fix URL shortening of some WA inputs
Diffstat (limited to '')
-rw-r--r--src/util/web.rs29
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(&quote_plus("1 * 2")?)?, "1%2B%252A%2B2");
+ Ok(())
+ }
+}
rtions'>+2 2021-10-20remove failing wolfram alpha test casesMax Audron-105/+55 this is due to the url shorterner dying randomly and also just generally bad idea to call external services during unit tests. 2021-10-20bump version to 1.6.2Max Audron-3/+2 2021-10-20prepare for release on crates.ioMax Audron-39/+65 2021-10-20add async docs to macro crate and bump versionMax Audron-9/+10 2021-10-20change hook errors to be logged as warningsMax Audron-3/+3 they in nearly all cases aren't critical enough to warrant an actual error messages 2021-10-20fix configuration not loading correctly on release buildsMax Audron-8/+23 2021-10-19replace sedregex crate8-rework-sedMax Audron-20/+358 This replaces the sedregex crate with our own implementation for multiple reasons: 1. We required to access the parsed regex, this required a patch to the sedregex crate which did not get merged due to an inactive dev, blocking us from publishing on crates.Io 2. We wanted to highlight the changes done in bold 3. We want to add execution of multiple chained sed commands in the future which would require more modification 2021-10-19add formatting trait for irc codesMax Audron-0/+129 add an impl off the formatting trait on String to format Strings with the typical irc formatting codes for bold, italic etc 2021-10-17fix links in readmeMax Audron-2/+2