Skip to content

Commit cd08794

Browse files
committed
Check if status and subject in badge generator is not empty
Signed-off-by: Benjamin Coenen <[email protected]>
1 parent a15f780 commit cd08794

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/web/badge/badge.rs

+11
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ impl Badge {
5353
};
5454
let v_metrics = font.v_metrics(scale);
5555
let offset = point(0.0, v_metrics.ascent);
56+
if options.status.is_empty() || options.subject.is_empty() {
57+
return Err(String::from("status and subject must not be empty"));
58+
}
5659
Ok(Badge {
5760
options: options,
5861
font: font,
@@ -145,6 +148,14 @@ mod tests {
145148
#[test]
146149
fn test_new() {
147150
assert!(Badge::new(options()).is_ok());
151+
152+
let mut bad_options_status = options();
153+
bad_options_status.status = "".to_owned();
154+
assert!(Badge::new(bad_options_status).is_err());
155+
156+
let mut bad_options_subject = options();
157+
bad_options_subject.subject = "".to_owned();
158+
assert!(Badge::new(bad_options_subject).is_err());
148159
}
149160

150161
#[test]

0 commit comments

Comments
 (0)