File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
3131
3232### Fixed bugs
3333
34+ * ` .gitignore ` with UTF-8 BOM can now be parsed correctly.
35+
3436## [ 0.39.0] - 2026-03-04
3537
3638### Release highlights
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ impl GitIgnoreFile {
6868 input : & [ u8 ] ,
6969 ) -> Result < Arc < Self > , GitIgnoreError > {
7070 let mut builder = gitignore:: GitignoreBuilder :: new ( prefix) ;
71- for ( i, input_line) in input. split ( |b| * b == b'\n' ) . enumerate ( ) {
71+ for ( i, input_line) in strip_bom ( input) . split ( |b| * b == b'\n' ) . enumerate ( ) {
7272 if input_line. starts_with ( b"#" ) {
7373 continue ;
7474 }
@@ -153,6 +153,10 @@ impl GitIgnoreFile {
153153 }
154154}
155155
156+ fn strip_bom ( text : & [ u8 ] ) -> & [ u8 ] {
157+ text. strip_prefix ( "\u{feff} " . as_bytes ( ) ) . unwrap_or ( text)
158+ }
159+
156160#[ cfg( test) ]
157161mod tests {
158162
@@ -408,6 +412,12 @@ mod tests {
408412 assert ! ( matches( b"a/x**y/b\n " , "a/xzzzy/b" ) ) ;
409413 }
410414
415+ #[ test]
416+ fn test_gitignore_with_utf8_bom ( ) {
417+ assert ! ( matches( b"\xef \xbb \xbf foo\n " , "foo" ) ) ;
418+ assert ! ( !matches( b"\n \xef \xbb \xbf foo\n " , "foo" ) ) ;
419+ }
420+
411421 #[ test]
412422 fn test_gitignore_line_ordering ( ) {
413423 assert ! ( matches( b"foo\n !foo/bar\n " , "foo" ) ) ;
You can’t perform that action at this time.
0 commit comments