Skip to content
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

universal newlines edge case: trailing \r\r treated as a single newline #4037

Closed
gitlab-importer opened this issue Nov 23, 2023 · 5 comments
Closed

Comments

@gitlab-importer
Copy link

In Heptapod by @dairiki on Nov 23, 2023, 07:11

I just stumbled across this by chance:

>>>> import io
>>>> io.TextIOWrapper(io.BytesIO(b"\r\r"), newline="").readlines()
['\r\r']  # wrong — this should be read as two lines
>>>> io.TextIOWrapper(io.BytesIO(b"\r\r\r\r"), newline="").readlines()
['\r', '\r', '\r\r']  # this should be four lines
>>>> io.TextIOWrapper(io.BytesIO(b"a\r\rb\r\r"), newline="").readlines()
['a\r', '\r', 'b\r\r']
>>>> io.TextIOWrapper(io.BytesIO(b"a\r\rb\r\rc"), newline="").readlines()
['a\r', '\r', 'b\r', '\r', 'c']  # ← this one is correct

I see the same behavior with both pypy3.9-7.3.13 and pypy3.10-7.3.13 (installed via pyenv)

The same bug happens when reading from a file.

It only happens with newline="" (universal newlines without newline translation). If newline is set to None, things seem to work as they are supposed to.

@gitlab-importer
Copy link
Author

In Heptapod by @cfbolz on Nov 23, 2023, 11:39

thanks for the report. ouch, this is annoying. from your examples it looks like only the last \r\r at the end are treated incorrectly, earlier in the file it seems to be ok? I'll look into it

@gitlab-importer
Copy link
Author

In Heptapod by @cfbolz on Nov 23, 2023, 15:17

mentioned in commit 5b31c9b32ef9c204de9b0671cdcb542a8c6f2e25

@gitlab-importer
Copy link
Author

In Heptapod by @cfbolz on Nov 23, 2023, 15:19

fixed in pypy2 in the above commit, now merging to pypy3

@gitlab-importer
Copy link
Author

In Heptapod by @cfbolz on Nov 28, 2023, 17:32

mentioned in commit 4e87fc16efa440c7368282311b0e5df6ebe4f237

@mattip
Copy link
Member

mattip commented Jan 19, 2024

Closing, should be fixed. Please open a new issue if needed.

@mattip mattip closed this as completed Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants