Repository: toml-rs/toml (language: rust)

Issue:
Incorrect BOM handling
This is a regression compared to toml-rs as found by cargo's tests

```
---- build::manifest_with_bom_is_ok stdout ----                                                                                                    
running `/home/epage/src/personal/cargo/target/debug/cargo build -v`                                                                               
thread 'build::manifest_with_bom_is_ok' panicked at '                                                                                              
test failed running `/home/epage/src/personal/cargo/target/debug/cargo build -v`                                                                   
error: process exited with code 101 (expected 0)                                                                                                   
--- stdout                                                                                                                                         
                                                                                                                                                   
--- stderr                                                                                                                                         
error: failed to parse manifest at `/home/epage/src/personal/cargo/target/tmp/cit/t286/foo/Cargo.toml`                                             
                                                                                                                                                   
Caused by:                                                                                                                                         
  could not parse input as TOML                                                                                                                    
                                                                                                                                                   
Caused by:                                                                                                                                         
  TOML parse error at line 1, column 1                                                                                                             
    |                                                                                                                                              
  1 | ﻿                                                                                                                                             
    | ^                                                                                                                                            
  Unexpected `ï`                                                                                                                                   
  Expected `end of input`                                                                                                                          
', tests/testsuite/build.rs:3168:25                                                                                                                
```


Discussion / hints:

Fix patch:
diff --git a/src/parser/document.rs b/src/parser/document.rs
index 3d42f483..4b3b1843 100644
--- a/src/parser/document.rs
+++ b/src/parser/document.rs
@@ -86,6 +86,9 @@ impl TomlParser {
     //                ( ws table ws [ comment ] ) /
     //                  ws )
     pub(crate) fn parse(s: &[u8]) -> Result<Document, TomlError> {
+        // Remove BOM if present
+        let s = s.strip_prefix(b"\xEF\xBB\xBF").unwrap_or(s);
+
         let mut parser = RefCell::new(Self::default());
         let input = Stream::new(s);
 
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index e8603ddd..c70c88cf 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -632,6 +632,25 @@ key = "value"
             assert_eq!(PrettyString(document), PrettyString(&doc.to_string()));
         }
 
+        let parse_only = ["\u{FEFF}
+[package]
+name = \"foo\"
+version = \"0.0.1\"
+authors = []
+"];
+        for document in &parse_only {
+            let doc = TomlParser::parse(document.as_bytes());
+            match doc {
+                Ok(_) => (),
+                Err(err) => {
+                    panic!(
+                        "Parse error: {}\nFailed to parse:\n```\n{}\n```",
+                        err, document
+                    )
+                }
+            }
+        }
+
         let invalid_inputs = [r#" hello = 'darkness' # my old friend
 $"#];
         for document in &invalid_inputs {


Test patch: