Skip to content
Myr

ignore/gitignore: skip BOM at start of ignore file

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This matches Git's behavior. Fixes #2177, Closes #2782

authored by Stephen Albert-Moore · committed by Andrew Gallant · parent c93fc79 · Browse files · 4 files+27 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+27 added−0 removed

  • tests:+19 added−0 removed
  • other:+8 added−0 removed

4 files+27 added−0 removed

modified:crates/ignore/src/gitignore.rs+6 added
400 unmodified lines
401 errs.push(Error::Io(err).tagged(path, lineno));402 break;403 }404 };405406 // Match Git's handling of .gitignore files that begin with the Unicode BOM407 const UTF8_BOM: &str = "\u{feff}";408 let line =409 if i == 0 { line.trim_start_matches(UTF8_BOM) } else { &line };410411 if let Err(err) = self.add_line(Some(path.to_path_buf()), &line) {412 errs.push(err.tagged(path, lineno));413 }414 }
409 unmodified lines
added:crates/ignore/tests/gitignore_skip_bom.gitignore+2 added
1ignore/this/path2# This file begins with a BOM (U+FEFF)
added:crates/ignore/tests/gitignore_skip_bom.rs+17 added
1use ignore::gitignore::GitignoreBuilder;23const IGNORE_FILE: &'static str = "tests/gitignore_skip_bom.gitignore";45/// Skip a Byte-Order Mark (BOM) at the beginning of the file, matching Git's6/// behavior.7///8/// Ref: <https://github.com/BurntSushi/ripgrep/issues/2177>9#[test]10fn gitignore_skip_bom() {11 let mut builder = GitignoreBuilder::new("ROOT");12 let error = builder.add(IGNORE_FILE);13 assert!(error.is_none(), "failed to open gitignore file");14 let g = builder.build().unwrap();1516 assert!(g.matched("ignore/this/path", false).is_ignore());17}
modified:CHANGELOG.md+2 added
9 unmodified lines
10 [BUG #2778](https://github.com/BurntSushi/ripgrep/issues/2778),11 [BUG #2836](https://github.com/BurntSushi/ripgrep/issues/2836),12 [BUG #2933](https://github.com/BurntSushi/ripgrep/pull/2933):13 Fix bug related to gitignores from parent directories.14* [BUG #2177](https://github.com/BurntSushi/ripgrep/issues/2177):15 Ignore a UTF-8 BOM marker at the start of `.gitignore` (and similar files).1617Feature enhancements:1819* [FEATURE #2708](https://github.com/BurntSushi/ripgrep/pull/2708):
1714 unmodified lines