Skip to content

BufferedReader.read_line undocumented behavior on new line characters #18751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
einar-hjortdal opened this issue Jul 2, 2023 · 4 comments
Open
Labels
Unit: Documentation Bugs/feature requests, that are related to the documentations.

Comments

@einar-hjortdal
Copy link
Contributor

einar-hjortdal commented Jul 2, 2023

Describe the issue

The documentation says the reader stops at \n but it does not do that: replies from a Redis server always end in \r\n and read_reply does not only stop at \n, it also stops at \r\n and does not return these characters.
This is a problem for me, I will have to rewrite using TcpConn.read instead and providing my own buffer.

Links

Problem was identified here
read_line

@einar-hjortdal einar-hjortdal added the Unit: Documentation Bugs/feature requests, that are related to the documentations. label Jul 2, 2023
@JalonSolov
Copy link
Contributor

Yes, the documentation should say that it reads until EOL, and returns the string without it.

read_line is not undocumented, simply slightly incorrectly documented.

If you want different behaviour, call BufferedReader.read instead of BufferedReader.read_line.

@Casper64
Copy link
Member

Casper64 commented Jul 3, 2023

Maybe I misunderstand the issue, but read_line does also stop at \r\n it's in the code:

// do some checking for whether we hit \r\n or just \n

It will actually check if there was a \r first and then returns the line without \r\n.

Or do you need to check whether the line ended in \r\n?

@einar-hjortdal
Copy link
Contributor Author

Or do you need to check whether the line ended in \r\n?

Yes I expected read_line to return the line including \n and the characters before it, since it is described as "stopping" there.

I have solved the problem by providing my own buffer and reading implementation on TcpConn.reader (since I am reading a TcpConn stream). Proper documentation would have saved me a lot of time I spent debugging the situation.

@JalonSolov
Copy link
Contributor

All of the read_line/read_lines routines in vlib return the line without the EOL. I don't see this explicitly documented, so the documentation could be improved.

It's done this way because that's what 99.9% of programs expect... the line without the EOL.

And you could still use read instead of read_line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unit: Documentation Bugs/feature requests, that are related to the documentations.
Projects
None yet
Development

No branches or pull requests

3 participants