Find url return string, not url

Need to change
This commit is contained in:
Skallwar 2019-11-04 21:13:26 +01:00
parent c43ba93e23
commit 358db4cea6

View file

@ -1,12 +1,11 @@
use regex::Regex;
use reqwest::Url;
pub fn find_urls(str: String) -> Vec<Url> {
pub fn find_urls(str: String) -> Vec<String> {
let regex = Regex::new(r#"(href|src) *= *"([^ "]*)""#).unwrap();
regex
.captures_iter(&str)
.map(|matched| Url::parse(&matched[2]))
.filter_map(Result::ok)
.map(|matched| String::from(&matched[2]))
.collect()
}
@ -17,6 +16,6 @@ mod tests {
#[test]
fn test_find_href_url() {
let vec = find_urls("href= \"https://lol.com\"\nsrc = \"ulr2\"".to_string());
assert_eq!(vec, [Url::parse("https://lol.com").unwrap()]);
assert_eq!(vec, ["https://lol.com", "url2"]);
}
}