Skip to content

Commit

Permalink
Prevent panic on empty tag/description (denisidoro#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Apr 13, 2020
1 parent cbae8a5 commit 3188a76
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "navi"
version = "2.5.0"
version = "2.5.1"
authors = ["Denis Isidoro <denis_isidoro@live.com>"]
edition = "2018"
description = "An interactive cheatsheet tool for the command-line"
Expand Down
12 changes: 10 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ fn read_file(
should_break = true
}
snippet = String::from("");
tags = String::from(&line[2..]);
tags = if line.len() > 2 {
String::from(&line[2..])
} else {
String::from("")
};
}
// metacomment
else if line.starts_with(';') {
Expand All @@ -175,7 +179,11 @@ fn read_file(
should_break = true
}
snippet = String::from("");
comment = String::from(&line[2..]);
comment = if line.len() > 2 {
String::from(&line[2..])
} else {
String::from("")
};
}
// variable
else if line.starts_with('$') {
Expand Down
13 changes: 12 additions & 1 deletion tests/cheats/more_cases.cheat
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ echo "http://google.com?q=<query>"
# fzf
ls / | fzf

#
echo description space

#
echo description blank

$ x: echo '1 2 3' | tr ' ' '\n'
$ y: echo 'a b c' | tr ' ' '\n'
$ z: echo 'foo bar' | tr ' ' '\n'
Expand All @@ -57,4 +63,9 @@ $ multiword: echo -e 'foo bar\nlorem ipsum\ndolor sit\nbaz'i
$ file: ls . --- --preview 'cat {}' --preview-window 'right:50%'

# this should be displayed
echo hi
echo hi

%

# Without tag
echo hi 1 2 3

0 comments on commit 3188a76

Please sign in to comment.