fix: avoid panic if input is empty

This commit is contained in:
Amaan Qureshi 2023-07-27 03:32:55 -04:00
parent ee399e67d4
commit 192793a6ab
No known key found for this signature in database
GPG key ID: E67890ADC4227273

View file

@ -95,7 +95,7 @@ pub fn parse_file_at_path(opts: ParseFileOptions) -> Result<bool> {
.collect::<Vec<_>>();
parser.parse_utf16(&source_code_utf16, None)
}
None if is_utf16_bom(&source_code[0..2]) => {
None if source_code.len() >= 2 && is_utf16_bom(&source_code[0..2]) => {
let source_code_utf16 = source_code
.chunks_exact(2)
.map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))