Skip to content

Commit

Permalink
feat: allow line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Oct 7, 2024
1 parent 643aa09 commit 5deecaf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/parsers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ impl<R: Read> BencodeParser<R> {
// End of list or dictionary (not end of integer)
self.end_bencoded_value(writer)?;
}
b'\n' => {
// Ignore line breaks at the beginning, the end or between values
}
_ => {
panic!("{}", format!("unexpected byte {} ({})", byte, byte as char));
}
Expand Down Expand Up @@ -272,6 +275,21 @@ mod tests {
assert_eq!(output, String::new());
}

#[test]
fn it_should_allow_line_breaks_at_the_beginning_of_the_input_stream() {
assert_eq!(to_json(b"\ni0e"), "0".to_string());
}

#[test]
fn it_should_allow_line_breaks_at_the_end_of_the_input_stream() {
assert_eq!(to_json(b"i0e\n"), "0".to_string());
}

#[test]
fn it_should_allow_line_breaks_between_bencoded_values() {
assert_eq!(to_json(b"li0e\ni1ee"), "[0,1]".to_string());
}

mod integers {
use crate::parsers::tests::to_json;

Expand Down

0 comments on commit 5deecaf

Please sign in to comment.