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

Strip BOM from ignore files #2178

Closed
wants to merge 1 commit into from
Closed

Conversation

tvrg
Copy link

@tvrg tvrg commented Apr 12, 2022

Fixes #2177

let rdr = io::BufReader::new(file);
let rdr = io::BufReader::new(
DecodeReaderBytesBuilder::new()
.bom_sniffing(false)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we actually want to enable bom_sniffing here. bom_sniffing(false) seems to be behavior preserving to me. But maybe we want to support ignore files in utf-16 as well?


fn get_gitignore() -> Gitignore {
let mut builder = GitignoreBuilder::new("ROOT");
let error = builder.add(IGNORE_FILE);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this as an integration test because the existing unit tests in gitignore.rs don't create any files but the logic to test is in GitignoreBuilder.add which only works on files.

I could also

  1. either add a unit test that creates a temporary gitignore file,
  2. or extract a method from add that works on a Read and test that. However, since the errors need the path, the extracted method would also need to know the path.

@tvrg tvrg changed the title ignore: strip BOM Strip BOM from ignore files Apr 12, 2022
@BurntSushi
Copy link
Owner

Thanks for the work on this. So to me, this is an overpowered solution. I do not think we need to bring in a absolutely enormous dependency on encoding_rs just to strip a few bytes from the prefix of a file that is usually small. I'd rather see this done manually. Hell, if it's easier, I'd prefer we just read the entire ignore file into memory. (Although I'd prefer not doing that.)

I'm going to close this PR because of its age (and because I'm working through the backlog), but if you want to try this again without encoding_rs that would be great. Otherwise I'm sure I'll get around to fixing it when I overhaul the ignore crate.

@BurntSushi BurntSushi closed this Jul 8, 2023
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

Successfully merging this pull request may close these issues.

First entry of gitignore searched if it starts with BOM
2 participants