diff --git a/src/provider.rs b/src/provider.rs index 61d166f..f47b9c2 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -25,6 +25,7 @@ pub fn load_signatures(input: &str) -> Result> { } pub fn parse_signatures(content: &str) -> Result> { + let content = content.strip_prefix(BOM).unwrap_or(content); let format = detect_format(content)?; let inputs = match format { Format::Json => parse_json(content)?, @@ -135,6 +136,18 @@ mod tests { assert_eq!(detect_format(csv).unwrap(), Format::Csv); } + #[test] + fn test_auto_detect_json_with_bom() { + let json = "\u{FEFF}[{\"r\":\"1\",\"s\":\"2\",\"z\":\"3\"}]"; + assert_eq!(detect_format(json).unwrap(), Format::Json); + } + + #[test] + fn test_auto_detect_csv_with_bom() { + let csv = "\u{FEFF}r,s,z\n1,2,3"; + assert_eq!(detect_format(csv).unwrap(), Format::Csv); + } + #[test] fn test_invalid_json_error() { let result = parse_signatures("not json"); @@ -212,4 +225,18 @@ mod tests { let sigs = parse_signatures(json).unwrap(); assert_eq!(sigs.len(), 1); } + + #[test] + fn test_parse_json_with_bom() { + let json = "\u{FEFF}[{\"r\":\"123\",\"s\":\"456\",\"z\":\"789\"}]"; + let sigs = parse_signatures(json).unwrap(); + assert_eq!(sigs.len(), 1); + } + + #[test] + fn test_parse_csv_with_bom() { + let csv = "\u{FEFF}r,s,z,pubkey\n123,456,789,\n"; + let sigs = parse_signatures(csv).unwrap(); + assert_eq!(sigs.len(), 1); + } }