1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-11-23 21:54:45 +02:00

ignore/gitignore: skip BOM at start of ignore file

This matches Git's behavior.

Fixes #2177, Closes #2782
This commit is contained in:
Stephen Albert-Moore
2024-04-17 16:58:23 -04:00
committed by Andrew Gallant
parent c93fc793a0
commit 483628469a
4 changed files with 27 additions and 0 deletions

View File

@@ -402,6 +402,12 @@ impl GitignoreBuilder {
break;
}
};
// Match Git's handling of .gitignore files that begin with the Unicode BOM
const UTF8_BOM: &str = "\u{feff}";
let line =
if i == 0 { line.trim_start_matches(UTF8_BOM) } else { &line };
if let Err(err) = self.add_line(Some(path.to_path_buf()), &line) {
errs.push(err.tagged(path, lineno));
}