Skip to content

Commit f3f3757

Browse files
committed
Auto append https:// on uris missing it
1 parent 123882b commit f3f3757

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/models/uri.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ pub struct Uri(Url);
77

88
impl Uri {
99
pub fn new(uri: &str) -> Self {
10-
Self(Url::parse(uri).expect("should be a valid url"))
10+
let uri = if uri.starts_with("https://") || uri.starts_with("http://") {
11+
uri
12+
} else {
13+
&format!("https://{uri}")
14+
};
15+
16+
let message = format!("should be a valid url: {uri}");
17+
Self(Url::parse(uri).unwrap_or_else(|_| panic!("{}", message)))
1118
}
1219
}
1320

0 commit comments

Comments
 (0)