diff --git a/crates/forge-core/src/issues.rs b/crates/forge-core/src/issues.rs
index e3c876a..c330af3 100644
--- a/crates/forge-core/src/issues.rs
+++ b/crates/forge-core/src/issues.rs
@@ -10,6 +10,8 @@ pub const MAX_TITLE: usize = 256;
pub const MAX_BODY: usize = 65536;
/// Longest accepted label name, in characters.
pub const MAX_LABEL_NAME: usize = 50;
+/// Longest label description, in characters.
+pub const MAX_LABEL_DESCRIPTION: usize = 500;
/// Most assignees one issue can have.
pub const MAX_ASSIGNEES: usize = 10;
@@ -251,7 +253,7 @@ pub fn validate_body(b: &str) -> Result<()> {
/// Returns `(trimmed name, normalized color)`. The name is 1..=50 characters with no control
/// characters. The color is `#rgb` or `#rrggbb` in any case and comes back as lowercase `#rrggbb`.
-pub fn validate_label(name: &str, color: &str) -> Result<(String, String)> {
+pub fn validate_label(name: &str, color: &str, description: &str) -> Result<(String, String)> {
let name = name.trim();
let len = name.chars().count();
if len == 0 || len > MAX_LABEL_NAME {
@@ -266,6 +268,11 @@ pub fn validate_label(name: &str, color: &str) -> Result<(String, String)> {
}
let color = normalize_color(color)
.ok_or_else(|| Error::Invalid(format!("label color {color:?} is not #rgb or #rrggbb")))?;
+ if description.chars().count() > MAX_LABEL_DESCRIPTION {
+ return Err(Error::Invalid(format!(
+ "label description must be at most {MAX_LABEL_DESCRIPTION} characters"
+ )));
+ }
Ok((name.to_string(), color))
}
@@ -321,18 +328,19 @@ mod tests {
#[test]
fn label_name_and_color_are_normalized() {
assert_eq!(
- validate_label(" bug ", "#FF0000").unwrap(),
+ validate_label(" bug ", "#FF0000", "").unwrap(),
("bug".to_string(), "#ff0000".to_string())
);
assert_eq!(
- validate_label("x", "#AbC").unwrap(),
+ validate_label("x", "#AbC", "").unwrap(),
("x".to_string(), "#aabbcc".to_string())
);
- assert!(validate_label("", "#fff").is_err());
- assert!(validate_label(" ", "#fff").is_err());
- assert!(validate_label(&"a".repeat(MAX_LABEL_NAME), "#fff").is_ok());
- assert!(validate_label(&"a".repeat(MAX_LABEL_NAME + 1), "#fff").is_err());
- assert!(validate_label("a\u{7}", "#fff").is_err());
+ assert!(validate_label("", "#fff", "").is_err());
+ assert!(validate_label(" ", "#fff", "").is_err());
+ assert!(validate_label(&"a".repeat(MAX_LABEL_NAME), "#fff", "").is_ok());
+ assert!(validate_label(&"a".repeat(MAX_LABEL_NAME + 1), "#fff", "").is_err());
+ assert!(validate_label("a\u{7}", "#fff", "").is_err());
+ assert!(validate_label("x", "#fff", &"d".repeat(MAX_LABEL_DESCRIPTION + 1)).is_err());
}
#[test]
@@ -340,7 +348,7 @@ mod tests {
for bad in [
"", "fff", "#ff", "#ffff", "#fffffff", "#gggggg", "red", "# fff", "#ff00 0",
] {
- assert!(validate_label("x", bad).is_err(), "{bad:?} accepted");
+ assert!(validate_label("x", bad, "").is_err(), "{bad:?} accepted");
}
}
diff --git a/crates/forge-core/src/store/labels.rs b/crates/forge-core/src/store/labels.rs
index 49c405b..af1527f 100644
--- a/crates/forge-core/src/store/labels.rs
+++ b/crates/forge-core/src/store/labels.rs
@@ -20,6 +20,8 @@ use crate::time::now_stamp;
/// Most assignees one issue can have.
pub const MAX_ASSIGNEES: usize = 10;
+/// Most labels one repo can have.
+pub const MAX_LABELS: i64 = 500;
const LABEL_TAKEN: &str = "a label with that name already exists";
const MILESTONE_TAKEN: &str = "a milestone with that title already exists";
@@ -92,7 +94,7 @@ impl Store {
color: &str,
description: &str,
) -> Result