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

std::str::Lines strips bare carriage return from end of string #106258

Closed
dfoxfranke opened this issue Dec 29, 2022 · 2 comments
Closed

std::str::Lines strips bare carriage return from end of string #106258

dfoxfranke opened this issue Dec 29, 2022 · 2 comments
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@dfoxfranke
Copy link

According to the documentation of std::string::Lines,

Lines are ended with either a newline (\n) or a carriage return with a line feed (\r\n).

The final line ending is optional. A string that ends with a final line ending will return the same lines as an otherwise identical string without a final line ending.

By my reading of these rules, a bare carriage return at the end of a string ought to be preserved, because a bare carriage return is not a line ending. That is, I expect the following:

    let lines : Vec<&'static str> = "one\r\ntwo\r".lines().collect();
    assert_eq!(lines[0], "one");
    assert_eq!(lines[1], "two\r");

In fact, this second assertion fails. The actual result is that lines[1] == "two".

Meta

rustc --version --verbose:

rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-unknown-linux-gnu
release: 1.66.0
LLVM version: 15.0.2
@dfoxfranke dfoxfranke added the C-bug Category: This is a bug. label Dec 29, 2022
@clubby789
Copy link
Contributor

This will be closed by #100311

@ChrisDenton ChrisDenton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 22, 2023
@ChrisDenton
Copy link
Member

I'm closing this as a duplicate of #94435. But I can reopen if need be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants