Skip to content

Commit

Permalink
fix: return error when format is empty in parse
Browse files Browse the repository at this point in the history
The format parsed in from_str maybe empty(eg. '%'). As a result,
cur_item may be None.
  • Loading branch information
cardigan1008 authored and ChristopherRabotin committed Apr 6, 2024
1 parent 54a9ef8 commit c28151d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/efmt/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ impl Format {
// Previous index of interest in the string
let mut prev_idx = 0;
let mut cur_item_idx = 0;
let mut cur_item = self.items[cur_item_idx].unwrap();
let mut cur_item = match self.items[cur_item_idx] {
Some(item) => item,
None => return Err(Errors::ParseError(ParsingErrors::UnknownFormat)),
};
let mut cur_token = cur_item.token;
let mut prev_item = cur_item;
let mut prev_token;
Expand Down

0 comments on commit c28151d

Please sign in to comment.