Skip to content

Commit

Permalink
Fix www url parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed Jul 21, 2024
1 parent 3bb8139 commit c74a7da
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions data/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,13 @@ pub fn parse_fragments(text: String) -> Content {
let mut fragments = vec![];

for (re_match, url) in URL_REGEX.find_iter(&text).filter_map(|re_match| {
Url::parse(re_match.as_str())
.ok()
.map(|url| (re_match, url))
let url = if re_match.as_str().starts_with("www") {
format!("https://{}", re_match.as_str())
} else {
re_match.as_str().to_string()
};

Url::parse(&url).ok().map(|url| (re_match, url))
}) {
if i < re_match.start() {
fragments.push(Fragment::Text(text[i..re_match.start()].to_string()));
Expand Down

0 comments on commit c74a7da

Please sign in to comment.