Skip to content

Commit 1aa7f0e

Browse files
committed
Remove support for parsing blobs and files
1 parent 24d96cc commit 1aa7f0e

2 files changed

Lines changed: 2 additions & 36 deletions

File tree

payjoin/src/core/into_url.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,6 @@ mod tests {
9898
assert_eq!(url.scheme(), "https");
9999
}
100100

101-
#[test]
102-
fn into_url_file_scheme() {
103-
let err = "file:///etc/hosts".into_url().unwrap_err();
104-
assert_eq!(err.to_string(), "URL scheme is not allowed");
105-
}
106-
107-
#[test]
108-
fn into_url_blob_scheme() {
109-
let err = "blob:https://example.com".into_url().unwrap_err();
110-
assert_eq!(err.to_string(), "URL scheme is not allowed");
111-
}
112-
113101
#[test]
114102
fn into_url_conversions() {
115103
let input = "http://localhost/";

payjoin/src/core/url.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use core::str::FromStr;
55
pub struct Url {
66
raw: String,
77
scheme: String,
8-
cannot_be_a_base: bool,
98
username: String,
109
password: Option<String>,
1110
host: Option<Host>,
@@ -114,39 +113,19 @@ impl FromStr for Url {
114113

115114
impl Url {
116115
pub fn parse(input: &str) -> Result<Url, ParseError> {
117-
let cannot_be_a_base = false;
118116
let (rest, scheme) = parse_scheme(input)?;
119117
let (_rest, host, port, path, query, fragment) =
120118
if let Some(rest) = rest.strip_prefix("://") {
121119
let (rest, host) = parse_host(rest)?;
122120
let (rest, port) = parse_port(rest).unwrap_or((rest, None));
123121
let (path, query, fragment) = parse_path_query_fragment(rest);
124-
125-
let is_empty_host = matches!(&host, Host::Domain(s) if s.is_empty());
126-
if is_empty_host && matches!(scheme.as_str(), "file" | "blob") {
127-
let after_colon = &input[scheme.len() + 1..];
128-
let (path, query, fragment) = parse_path_query_fragment(after_colon);
129-
(rest, None, None, path, query, fragment)
130-
} else {
131-
(rest, Some(host), port, path, query, fragment)
132-
}
133-
} else if let Some(rest) = rest.strip_prefix(":") {
134-
let (path, query, fragment) = parse_path_query_fragment(rest);
135-
(rest, None, None, path, query, fragment)
122+
(rest, Some(host), port, path, query, fragment)
136123
} else {
137124
return Err(ParseError::InvalidFormat);
138125
};
139126

140127
let host = match host {
141-
Some(ref h) if h.is_empty() =>
142-
if matches!(scheme.as_str(), "file" | "blob") {
143-
None
144-
} else {
145-
return Err(ParseError::EmptyHost);
146-
},
147-
None if !matches!(scheme.as_str(), "file" | "blob") => {
148-
return Err(ParseError::EmptyHost);
149-
}
128+
Some(ref h) if h.is_empty() => return Err(ParseError::EmptyHost),
150129
_ => host,
151130
};
152131

@@ -157,7 +136,6 @@ impl Url {
157136
let mut url = Url {
158137
raw: String::new(),
159138
scheme,
160-
cannot_be_a_base,
161139
username,
162140
password,
163141
host,

0 commit comments

Comments
 (0)