allow 2-letter, 24-letter tags

This commit is contained in:
2026-02-25 17:14:43 +01:00
parent 11476f7c5b
commit edc8ea1598

View File

@@ -90,9 +90,9 @@ pub struct TagName(String);
#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq, Serialize)] #[derive(Debug, thiserror::Error, Clone, PartialEq, Eq, Serialize)]
pub enum TagNameError { pub enum TagNameError {
#[error("Tag is too short - must be 3 or more characters.")] #[error("Tag is too short - must be 2 or more characters.")]
TagTooShort, TagTooShort,
#[error("Tag is too long - must be 16 or less characters.")] #[error("Tag is too long - must be 24 or less characters.")]
TagTooLong, TagTooLong,
#[error("Tag must consist of ASCII alphanumerics or mid-tag dashes only.")] #[error("Tag must consist of ASCII alphanumerics or mid-tag dashes only.")]
TagNonDashAsciiAlphanumeric, TagNonDashAsciiAlphanumeric,
@@ -110,8 +110,8 @@ impl TagName {
} }
pub fn validate_str(str: &str) -> Result<(), TagNameError> { pub fn validate_str(str: &str) -> Result<(), TagNameError> {
match str.len() { match str.len() {
..=2 => return Err(TagNameError::TagTooShort), ..2 => return Err(TagNameError::TagTooShort),
17.. => return Err(TagNameError::TagTooLong), 25.. => return Err(TagNameError::TagTooLong),
_ => (), _ => (),
}; };
if str.bytes().any(|c| !c.is_ascii_alphanumeric() && c != b'-') { if str.bytes().any(|c| !c.is_ascii_alphanumeric() && c != b'-') {
@@ -212,12 +212,20 @@ fn tagname_consecutive_dash_fail() {
#[test] #[test]
#[should_panic] #[should_panic]
fn tagname_short_fail() { fn tagname_short_fail() {
TagName::new("x").unwrap();
}
#[test]
fn tagname_short_pass() {
TagName::new("xd").unwrap(); TagName::new("xd").unwrap();
} }
#[test] #[test]
#[should_panic] #[should_panic]
fn tagname_long_fail() { fn tagname_long_fail() {
TagName::new("xddddddddddddddddddddddddddd").unwrap(); TagName::new("1234567890123456789012345").unwrap();
}
#[test]
fn tagname_long_pass() {
TagName::new("123456789012345678901234").unwrap();
} }
#[test] #[test]
#[should_panic] #[should_panic]