Skip to content

Commit

Permalink
Added additional verification of status line
Browse files Browse the repository at this point in the history
  • Loading branch information
CKingX committed May 20, 2022
1 parent e583c5d commit e6326fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub const NO_CURRENT_POSITION_ERROR: &str = "Current position in status line is
pub const NO_CURRENT_STATUS_ERROR: &str = "Current status is missing from the status line";
pub const UNKNOWN_CURRENT_STATUS_ERROR: &str = "Invalid status in status line";
pub const UNKNOWN_CURRRENT_PHASE_ERROR: &str = "Invalid phase in status line";
pub const CURRENT_PHASE_LESS_THAN_ONE_ERROR: &str =
"Invalid phase in status line: phase must be 1 or greater";

pub fn file_not_found(filetype: FileType) -> String {
format!("{FILE_NOT_FOUND_ERROR} {}", filetype.to_string())
Expand Down
10 changes: 9 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,22 @@ where
match current_pass {
Some(x) => {
let x_location = get_next(current_status_location + 1, line, x);
x.parse::<u8>().unwrap_or_else(|_| {
let current_status = x.parse::<u8>().unwrap_or_else(|_| {
report_error(
&line_content,
x_location,
x,
error::UNKNOWN_CURRRENT_PHASE_ERROR,
)
});
if current_status < 1 {
report_error(
&line_content,
x_location,
x,
error::CURRENT_PHASE_LESS_THAN_ONE_ERROR,
);
}
}
None => (),
};
Expand Down

0 comments on commit e6326fd

Please sign in to comment.