Lukas Atkinso: Net-Negative Cursor (lukasatkinson.de)
from HaraldvonBlauzahn@feddit.org to programming@programming.dev on 01 Jun 04:07
https://feddit.org/post/13417271

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.

#programming

threaded - newest

HaraldvonBlauzahn@feddit.org on 01 Jun 04:12 next collapse
let mut bytes = vec![0u8; len as usize];
    buf.read_exact(&mut bytes)?;

// Sanitize control characters
let sanitized_bytes: Vec<u8> = bytes.into_iter()
    .filter(|&b| b >= 32 || b == 9 || b == 10 || b == 13) // Allow space, tab, newline, carriage return
    .collect();


This implicitly, and wrongly, swaps the interpretation of the input from UTF8 text to pure ASCII.

setsubyou@lemmy.world on 01 Jun 07:08 collapse

In UTF8, all bytes that are not an ASCII character have the high bit set.

sxan@midwest.social on 01 Jun 09:19 next collapse

This person Unicodes

HaraldvonBlauzahn@feddit.org on 01 Jun 09:40 collapse

You are right with this. But still, in Rust, a vector of u8 is different from a sequence of unicode characters. This would not work in Python3 either, while it’d work in Python2.

brian@programming.dev on 01 Jun 14:33 next collapse

yeah it’s incorrect bc it destroys multibyte characters, but no idea what you’re saying about u8 being a different type from unicode. the original code was reading bytes and converting them too? the typing isn’t the issue, you can still store utf8 as a series of bytes

Markaos@discuss.tchncs.de on 01 Jun 15:34 collapse

it’s incorrect bc it destroys multibyte characters

It doesn’t. As the poster two levels up said, all bytes that don’t represent an ASCII character have the high bit set, even the follow-up bytes in multibyte sequences. So the condition b >= 32 will match and preserve them.

brian@programming.dev on 01 Jun 16:00 collapse

yeah fair enough. that wasn’t really my point and I wasn’t paying attention

FizzyOrange@programming.dev on 01 Jun 16:37 collapse

No, the filter is correct even for UTF-8. Any ASCII character is exactly unchanged in UTF-8 (part of the reason it is popular). Since this code only filters out ASCII characters it works fine with ASCII or UTF-8.

[deleted] on 01 Jun 21:25 collapse
.
Kissaki@programming.dev on 01 Jun 08:28 next collapse

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: lukasatkinson.de/2025/net-negative-cursor/

HaraldvonBlauzahn@feddit.org on 01 Jun 09:22 collapse

Thanks, I fixed it!

A_norny_mousse@feddit.org on 01 Jun 10:14 next collapse

Not a coder but I grasped enough.

Lastly, I’d like to know where the AI got the idea from. Sounds like pizza glue.

FizzyOrange@programming.dev on 01 Jun 16:39 collapse

I don’t think this is a very interesting article. We already know AI suggests nonsense a lot of the time. That in no way demonstrates that it is net-negative. In my experience it’s a net positive even accounting for the times it gets things wrong.

Yes you do have to review its code closely. News at 10.

It is kind of funny that they picked an example where it made an obvious mistake for their hero image though.