From 187cadaa01c47f87ac61c05b40e12e15cd6a93e9 Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Fri, 15 Nov 2024 15:45:36 +0800 Subject: [PATCH 1/2] feat: allow underscore in publish url --- src/biz/workspace/publish.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/biz/workspace/publish.rs b/src/biz/workspace/publish.rs index e2c2d26f..61d78df7 100644 --- a/src/biz/workspace/publish.rs +++ b/src/biz/workspace/publish.rs @@ -74,7 +74,7 @@ fn check_collab_publish_name(publish_name: &str) -> Result<(), AppError> { // Only contain alphanumeric characters and hyphens for c in publish_name.chars() { - if !c.is_alphanumeric() && c != '-' { + if !c.is_alphanumeric() && c != '-' && c != '_' { return Err(AppError::PublishNameInvalidCharacter { character: c }); } } @@ -246,8 +246,9 @@ pub async fn list_collab_publish_info( async fn check_workspace_namespace(new_namespace: &str) -> Result<(), AppError> { // Must be url safe // Only contain alphanumeric characters and hyphens + // and underscores (discouraged) for c in new_namespace.chars() { - if !c.is_alphanumeric() && c != '-' { + if !c.is_alphanumeric() && c != '-' && c != '_' { return Err(AppError::CustomNamespaceInvalidCharacter { character: c }); } } From 4703b90751f14fc222eb13fdb0f353c715870f77 Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Fri, 15 Nov 2024 16:37:02 +0800 Subject: [PATCH 2/2] fix: modify test case for underscore --- tests/workspace/publish.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/workspace/publish.rs b/tests/workspace/publish.rs index 5296a50b..72f774d0 100644 --- a/tests/workspace/publish.rs +++ b/tests/workspace/publish.rs @@ -39,7 +39,7 @@ async fn test_set_publish_namespace_set() { .unwrap(); } - let new_namespace = uuid::Uuid::new_v4().to_string(); + let new_namespace = format!("namespace_{}", uuid::Uuid::new_v4()); c.set_workspace_publish_namespace(&workspace_id.to_string(), new_namespace.clone()) .await .unwrap(); @@ -156,9 +156,9 @@ async fn test_publish_doc() { assert_eq!(err.code, ErrorCode::PublishNameTooLong, "{:?}", err); } - let publish_name_1 = "publish-name-1"; + let publish_name_1 = "publish_name-1"; let view_id_1 = uuid::Uuid::new_v4(); - let publish_name_2 = "publish-name-2"; + let publish_name_2 = "publish_name-2"; let view_id_2 = uuid::Uuid::new_v4(); // User publishes two collabs