commit 61b42c929d8c501293581456fcb10440d20a88f8
parent fe9679fdf12df2c303aa0093b54ed053decb6b52
Author: alex wennerberg <alex@alexwennerberg.com>
Date: Thu, 18 Nov 2021 22:00:08 -0800
Allow UTF8
Diffstat:
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/finger.rs b/finger.rs
@@ -13,11 +13,10 @@
// The finger protocol is featured heavily in Elif Batuman's Pulitizer Prize nominated novel The Idiot.
// FINGER > FACEBOOK
-use std::env;
-use std::io;
use std::io::prelude::*;
use std::net::TcpStream;
use std::process;
+use std::{env, io, str};
// supports standard finger queries and URIs
// From the drat spec:
@@ -74,16 +73,7 @@ fn main() -> std::io::Result<()> {
// TODO -- filter out nonprintable
stream.read_to_end(&mut line)?;
- let mut stdout = io::stdout();
- for byte in line.iter() {
- // RFC 1288: "this program
- // SHOULD filter any unprintable data, leaving only printable 7-bit
- // characters (ASCII 32 through ASCII 126), tabs (ASCII 9), and CRLFs."
- if (*byte >= 32 && *byte <= 126) || *byte == 9 || *byte == 10 || *byte == 13 {
- // probably a more efficient way of doing this
- stdout.write_all(&[*byte])?;
- }
- }
- println!("");
+ // Assume UTF-8 input, against the spec, which predates UTF8
+ println!("{}", str::from_utf8(&line).unwrap());
Ok(())
}