…which occour implicitly when checking out the repository fixtures on windows, which are then windows formatted. From there the unholy carriage return \r enters the compiled binary using include_bytes! as a template, which then is used to initialize a repository. In case of bare repositories, the implementation has to check if it really is bare (i.e. bare = true) or just looks bare (because there is no index, but that's the case in a new repository as well). This check would use the config parser, which wouldn't consider carriage returns and fail to parse the config file, making the opening of repositories impossible on windows.
Unified · Split
| @@ -1367,7 +1367,7 @@ fn take_spaces(i: &[u8]) -> IResult<&[u8], &str> { · 1366 unmodified lines | ||
| 1367 | 1367 | |
| 1368 | 1368 | fn take_newline(i: &[u8]) -> IResult<&[u8], (&str, usize)> { |
| 1369 | 1369 | let mut counter = 0; |
| 1370 | − let (i, v) = take_while(|c| (c as char).is_ascii() && is_newline(c))(i)?; | |
| 1370 | + let (i, v) = take_while(|c| (c as char).is_ascii() && (c == b'\r' || is_newline(c)))(i)?; | |
| 1371 | 1371 | counter += v.len(); |
| 1372 | 1372 | if v.is_empty() { |
| 1373 | 1373 | Err(nom::Err::Error(NomError { |
| @@ -0,0 +1,14 @@ | ||
| 1 | +; hello | |
| 2 | +# world | |
| 3 | + | |
| 4 | +[core] | |
| 5 | + repositoryformatversion = 0 | |
| 6 | + bare = true | |
| 7 | +[other] | |
| 8 | + repositoryformatversion = 0 | |
| 9 | + | |
| 10 | + bare = true | |
| 11 | + | |
| 12 | +# before section with newline | |
| 13 | +[foo] | |
| 14 | + repositoryformatversion = 0 | |
| @@ -1,6 +1,14 @@ | ||
| 1 | 1 | use std::{borrow::Cow, convert::TryFrom}; |
| 2 | 2 | |
| 3 | 3 | use git_config::{file::GitConfig, values::*}; |
| 4 | +use std::path::Path; | |
| 5 | + | |
| 6 | +#[test] | |
| 7 | +fn parse_config_with_windows_line_endings_successfully() { | |
| 8 | + GitConfig::open(Path::new("tests").join("fixtures").join("repo-config.crlf")) | |
| 9 | + .map_err(|err| err.to_string()) | |
| 10 | + .unwrap(); | |
| 11 | +} | |
| 4 | 12 | |
| 5 | 13 | /// Asserts we can cast into all variants of our type |
| 6 | 14 | #[test] |