Commit cd42365
committed
library: core::str::lines: Fix handling of trailing bare CR
E.g., split "bare\r" into the single line "bare\r", not "bare".
The documentation for this function says that only LF or CR-LF count
as newlines. So a bare CR is not a line ending, and must not be
stripped.
This fix is a behavioural change, even though it brings the behaviour
into line with the documentation, and into line with that of
`std::io::BufRead:;lines()`.
It seems unlikely that anyone is relying on this bug, but I'm not sure
how to rule it out. Perhaps this should have an FCP or a crater run or
something. It should definitely be in the release notes.
This is an alternative to rust-lang#91051, which proposes to document rather
than fix the behaviour.
As for the implementation: the current version doesn't give the map
closure the right information, so we need to use split_inclusive.
After that, we can reuse the logic in the new `str::trim_newline`.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>1 parent 825eab4 commit cd42365
2 files changed
+6
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
1095 | 1095 | | |
1096 | 1096 | | |
1097 | 1097 | | |
1098 | | - | |
| 1098 | + | |
1099 | 1099 | | |
1100 | 1100 | | |
1101 | 1101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
913 | 913 | | |
914 | 914 | | |
915 | 915 | | |
916 | | - | |
| 916 | + | |
917 | 917 | | |
918 | 918 | | |
919 | 919 | | |
920 | 920 | | |
921 | 921 | | |
922 | | - | |
| 922 | + | |
923 | 923 | | |
924 | 924 | | |
925 | 925 | | |
| |||
2558 | 2558 | | |
2559 | 2559 | | |
2560 | 2560 | | |
2561 | | - | |
2562 | | - | |
2563 | | - | |
2564 | | - | |
| 2561 | + | |
| 2562 | + | |
2565 | 2563 | | |
2566 | 2564 | | |
2567 | 2565 | | |
| |||
0 commit comments