Browse Source

[gopher] only extract URLs from lines starting with '['

tags/0.8.7
Julien Blanchard 1 year ago
parent
commit
fece502d1d
2 changed files with 7 additions and 12 deletions
  1. 5
    1
      src/gopher/client.rs
  2. 2
    11
      src/gopher/link.rs

+ 5
- 1
src/gopher/client.rs View File

@@ -31,7 +31,11 @@ pub fn get_data<T: Protocol>(url: T) -> Result<(Option<Vec<u8>>, Vec<u8>), Strin
31 31
                     None => format!("{}\r\n", path),
32 32
                 };
33 33
 
34
-                let url = if url.starts_with("/0") || url.starts_with("/1") || url.starts_with("/g")  || url.starts_with("/I")  || url.starts_with("/9")
34
+                let url = if url.starts_with("/0")
35
+                    || url.starts_with("/1")
36
+                    || url.starts_with("/g")
37
+                    || url.starts_with("/I")
38
+                    || url.starts_with("/9")
35 39
                 {
36 40
                     url.split_off(2)
37 41
                 } else if url == "/\n" {

+ 2
- 11
src/gopher/link.rs View File

@@ -143,11 +143,10 @@ impl FromStr for Link {
143 143
                 Err(ParseError)
144 144
             }
145 145
         } else if line.starts_with('[') {
146
-            let mut url = String::from(line);
147
-            let url = url.split_off(4);
146
+            let url = extract_url(line);
148 147
             let label = String::from(line);
149 148
 
150
-            match make_link(url, label) {
149
+            match make_link(String::from(url), label) {
151 150
                 Some(link) => Ok(link),
152 151
                 None => Err(ParseError),
153 152
             }
@@ -171,14 +170,6 @@ impl FromStr for Link {
171 170
             } else {
172 171
                 Err(ParseError)
173 172
             }
174
-        } else if line.contains("://") {
175
-            let url = extract_url(line);
176
-            let label = String::from(line);
177
-
178
-            match make_link(String::from(url), label) {
179
-                Some(link) => Ok(link),
180
-                None => Err(ParseError),
181
-            }
182 173
         } else {
183 174
             Err(ParseError)
184 175
         }

Loading…
Cancel
Save