~exprez135/castor

fece502d1d7a8478e26218b391130f41acd184fe — Julien Blanchard 1 year, 5 months ago bb7926a
[gopher] only extract URLs from lines starting with '['
2 files changed, 7 insertions(+), 12 deletions(-)

M src/gopher/client.rs
M src/gopher/link.rs
M src/gopher/client.rs => src/gopher/client.rs +5 -1
@@ 31,7 31,11 @@ pub fn get_data<T: Protocol>(url: T) -> Result<(Option<Vec<u8>>, Vec<u8>), Strin
                    None => format!("{}\r\n", path),
                };

                let url = if url.starts_with("/0") || url.starts_with("/1") || url.starts_with("/g")  || url.starts_with("/I")  || url.starts_with("/9")
                let url = if url.starts_with("/0")
                    || url.starts_with("/1")
                    || url.starts_with("/g")
                    || url.starts_with("/I")
                    || url.starts_with("/9")
                {
                    url.split_off(2)
                } else if url == "/\n" {

M src/gopher/link.rs => src/gopher/link.rs +2 -11
@@ 143,11 143,10 @@ impl FromStr for Link {
                Err(ParseError)
            }
        } else if line.starts_with('[') {
            let mut url = String::from(line);
            let url = url.split_off(4);
            let url = extract_url(line);
            let label = String::from(line);

            match make_link(url, label) {
            match make_link(String::from(url), label) {
                Some(link) => Ok(link),
                None => Err(ParseError),
            }


@@ 171,14 170,6 @@ impl FromStr for Link {
            } else {
                Err(ParseError)
            }
        } else if line.contains("://") {
            let url = extract_url(line);
            let label = String::from(line);

            match make_link(String::from(url), label) {
                Some(link) => Ok(link),
                None => Err(ParseError),
            }
        } else {
            Err(ParseError)
        }