Skip to content

Commit a5ebd69

Browse files
committed
skip the BOM as well (#301)
1 parent 7ddc43e commit a5ebd69

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-attributes/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ doctest = false
1515
[dependencies]
1616
bstr = { version = "0.2.13", default-features = false, features = ["std"]}
1717
bitflags = "1.3.2"
18+
unicode-bom = "1.1.4"
1819

1920
[dev-dependencies]
2021
git-testtools = { path = "../tests/tools"}

git-attributes/src/parse/ignore.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ pub struct Iter<'a> {
88

99
impl<'a> Iter<'a> {
1010
pub fn new(buf: &'a [u8]) -> Self {
11+
let bom = unicode_bom::Bom::from(buf);
1112
Iter {
12-
lines: buf.lines(),
13+
lines: buf[bom.len()..].lines(),
1314
line_no: 0,
1415
}
1516
}

git-attributes/tests/parse/ignore.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
use git_attributes::ignore::pattern::Mode;
22
use git_testtools::fixture_path;
33

4+
#[test]
5+
fn byte_order_marks_are_no_patterns() {
6+
assert_eq!(
7+
git_attributes::parse::ignore("\u{feff}hello".as_bytes()).next(),
8+
Some((r"hello".into(), Mode::NO_SUB_DIR, 1))
9+
);
10+
}
11+
412
#[test]
513
fn line_numbers_are_counted_correctly() {
614
let ignore = std::fs::read(fixture_path("ignore/various.txt")).unwrap();

0 commit comments

Comments
 (0)