Skip to content
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

refactor(document): add web document service api #2904

Merged
merged 13 commits into from
Aug 19, 2024
19 changes: 18 additions & 1 deletion ee/tabby-schema/src/schema/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lazy_static! {
pub static ref REPOSITORY_NAME_REGEX: Regex = Regex::new("^[a-zA-Z][\\w.-]+$").unwrap();
pub static ref USERNAME_REGEX: Regex =
Regex::new(r"^[^0-9±!@£$%^&*_+§¡€#¢¶•ªº«\\/<>?:;|=.,]{2,20}$").unwrap();
pub static ref DOCUMENT_NAME_REGEX: Regex = Regex::new(r"^[A-Za-z][A-Za-z0-9]*$").unwrap();
pub static ref WEB_DOCUMENT_NAME_REGEX: Regex = Regex::new(r"^[A-Za-z][A-Za-z0-9_]*$").unwrap();
wsxiaoys marked this conversation as resolved.
Show resolved Hide resolved
}

#[cfg(test)]
wsxiaoys marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -41,4 +41,21 @@ mod tests {
assert_eq!(result, expected, "Failed for name: {}", name);
}
}

#[test]
fn test_web_document_name_regex() {
let test_cases = vec![
("John", true), // English name
("Müller", false), // German name
("abc123", true),
("Abc_123", true),
("_abc_123", false),
("abc123*", false),
];

for (name, expected) in test_cases {
let result = WEB_DOCUMENT_NAME_REGEX.is_match(name);
assert_eq!(result, expected, "Failed for name: {}", name);
}
}
}
4 changes: 2 additions & 2 deletions ee/tabby-schema/src/schema/web_documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl CustomWebDocument {
pub struct CreateCustomDocumentInput {
#[validate(regex(
code = "name",
path = "*crate::schema::constants::DOCUMENT_NAME_REGEX",
path = "*crate::schema::constants::WEB_DOCUMENT_NAME_REGEX",
message = "Invalid document name"
))]
pub name: String,
Expand All @@ -52,7 +52,7 @@ pub struct CreateCustomDocumentInput {
pub struct SetPresetDocumentActiveInput {
#[validate(regex(
code = "name",
path = "*crate::schema::constants::DOCUMENT_NAME_REGEX",
path = "*crate::schema::constants::WEB_DOCUMENT_NAME_REGEX",
message = "Invalid document name"
))]
pub name: String,
xxs-wallace marked this conversation as resolved.
Show resolved Hide resolved
wsxiaoys marked this conversation as resolved.
Show resolved Hide resolved
Expand Down