Skip to content

Remove a couple of possible panics when opening a post #1132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/posts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ impl Post {
let filename = split.next().unwrap().to_string();

let contents = std::fs::read_to_string(path)?;
if contents.len() < 5 {
return Err(
format!("{path:?} is empty, or too short to have valid front matter").into(),
);
}

// yaml headers.... we know the first four bytes of each file are "---\n"
// so we need to find the end. we need the fours to adjust for those first bytes
let end_of_yaml = contents[4..].find("---").unwrap() + 4;
let end_of_yaml = contents[4..].find("---\n").unwrap() + 4;
let yaml = &contents[..end_of_yaml];
let YamlHeader {
author,
Expand Down