What I think in addition to what Atkinso writes: If you just strip arbitrary bytes that happen to be equal in value to the numeric value of ASCII control characters or whitespace, how can you be sure that you don’t destroy valid non-whitespace unicode symbols?

You can’t! This will work only of you have actually ASCII input.

  • @Kissaki@programming.dev
    link
    fedilink
    English
    6
    edit-2
    2 days ago

    The link is broken. Looks like code was accidentally pasted there.

    https://lukasatkinson.de/2025/net-negative-cursor/%20%20%20%20let%20mut%20bytes%20=%20vec![0u8;%20len%20as%20usize];%20%20%20%20buf.read_exact(&mut%20bytes)?%3B++++++++%2F%2F+Sanitize+control+characters+++++let+sanitized_bytes%3A+Vec%3Cu8%3E+=+bytes.into_iter%28%29+++++++++.filter%28%7C&b%7C+b+%3E=+32+%7C%7C+b+%3D%3D+9+%7C%7C+b+%3D%3D+10+%7C%7C+b+%3D%3D+13%29+%2F%2F+Allow+space%2C+tab%2C+newline%2C+carriage+return++++.collect%28%29%3B
    

    404 Page Not Found
    The page you have requested does not exist. Would you like to visit the start page?

    Cleaned up link: https://lukasatkinson.de/2025/net-negative-cursor/