Fix parser panic (#5820)

This commit is contained in:
Reilly Wood
2022-06-17 14:11:48 -04:00
committed by GitHub
parent 28c21121cf
commit 2caa44cea8
4 changed files with 26 additions and 3 deletions

View File

@ -22,6 +22,7 @@ use crate::parse_keywords::{
parse_use,
};
use itertools::Itertools;
use log::trace;
use std::{
collections::{HashMap, HashSet},
@ -1206,9 +1207,13 @@ fn parse_binary_with_base(
}
fn decode_with_base(s: &str, base: u32, digits_per_byte: usize) -> Result<Vec<u8>, ParseIntError> {
(0..s.len())
.step_by(digits_per_byte)
.map(|i| u8::from_str_radix(&s[i..i + digits_per_byte], base))
s.chars()
.chunks(digits_per_byte)
.into_iter()
.map(|chunk| {
let str: String = chunk.collect();
u8::from_str_radix(&str, base)
})
.collect()
}