From 8072e6f1d188119100a933a1a46461201bbec252 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 27 Nov 2026 18:58:37 +0300 Subject: [PATCH] Count Unicode characters consistently in group names --- CHANGELOG.md | 2 ++ core/src/admin.rs | 2 ++ core/src/admin_extra.rs | 4 ++-- core/tests/bridge_smoke.rs | 16 ++++++++++++++++ docs/mobile-port-progress.md | 2 ++ native/src/ui/shell/forms.rs | 16 ++++++++++++++-- 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91ca1ed..1c20169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Server and channel group names use the same 128-character Unicode limit in the editor and core. Multibyte names no longer fail early because of their UTF-8 byte length. + - Administrative commands reject IDs, log offsets and editable numeric properties above the reference interface's safe-integer limit before connecting. Server quota, bandwidth and default-group fields enforce the same limit in the native editor. - Desktop users can select multiple files in the channel upload dialog. Selections above 100 files are rejected as a batch; cancelling or reconnecting does not queue files in another session. diff --git a/core/src/admin.rs b/core/src/admin.rs index 0468321..ba6cc86 100644 --- a/core/src/admin.rs +++ b/core/src/admin.rs @@ -24,6 +24,8 @@ pub mod extra; /// Upper bound for rows collected for one list request. pub const MAX_ROWS: usize = 10_000; +/// Maximum number of Unicode scalar values in a server or channel group name. +pub const MAX_GROUP_NAME_CHARS: usize = 128; /// Inclusive limit for integer arguments shared with the reference command interface. pub const MAX_SAFE_INTEGER: u64 = (1 << 53) - 1; const MAX_TEXT: usize = 8192; diff --git a/core/src/admin_extra.rs b/core/src/admin_extra.rs index 1bc6591..d410acb 100644 --- a/core/src/admin_extra.rs +++ b/core/src/admin_extra.rs @@ -68,8 +68,8 @@ impl Command { Self::ClientDatabaseFind{pattern,..}=>text(pattern,255)?, Self::ClientDatabaseId{uid}=>text(uid,128)?, Self::ClientDatabaseDelete{client_database_id,confirm,..}=>{positive(*client_database_id)?;if confirm!=&client_database_id.to_string(){return Err(menu::bad("confirmation does not match the database ID"));}}, - Self::GroupAdd{name,group_type,..}=>{text(name,128)?;if *group_type>2{return Err(menu::bad("type must be 0..2"));}}, - Self::GroupRename{group_id,name,..}=>{positive(*group_id)?;text(name,128)?;}, + Self::GroupAdd{name,group_type,..}=>{super::check_str("name",name,super::MAX_GROUP_NAME_CHARS,false)?;if *group_type>2{return Err(menu::bad("type must be 0..2"));}}, + Self::GroupRename{group_id,name,..}=>{positive(*group_id)?;super::check_str("name",name,super::MAX_GROUP_NAME_CHARS,false)?;}, Self::GroupSetPermissions{group_id,permissions,kind,..}=>{positive(*group_id)?;validate_permissions(permissions,*kind==GroupKind::Server)?;}, Self::ChannelSetPermissions{channel_id,permissions,..}=>{positive(*channel_id)?;validate_permissions(permissions,false)?;}, Self::GroupDelete{group_id,confirm,..}=>{positive(*group_id)?;if confirm!=&group_id.to_string(){return Err(menu::bad("confirmation does not match the group ID"));}}, diff --git a/core/tests/bridge_smoke.rs b/core/tests/bridge_smoke.rs index 8e36bbc..2dcba83 100644 --- a/core/tests/bridge_smoke.rs +++ b/core/tests/bridge_smoke.rs @@ -330,6 +330,22 @@ fn connect_and_disconnect_validate_arguments_before_network_io() { core.shutdown(); } +#[test] +fn unicode_group_names_are_validated_before_connecting() { + let dir=TempDir::new("unicode-group-names"); + let mut core=Core::start(&dir.0); + let limit="я".repeat(127)+"\u{1f3b5}"; + for (cmd,mut args) in [("group_add",json!({"generation":1,"kind":"server","type":1})), + ("group_rename",json!({"generation":1,"kind":"channel","group_id":3}))] { + for (name,code) in [(limit.clone(),"not_connected"),(format!("{limit}x"),"bad_request"),("line\nbreak".into(),"bad_request")] { + args["name"]=json!(name); + let (reply,_)=core.request("group-name",cmd,args.clone()); + assert_eq!(reply["error"]["code"],code,"{cmd}: {reply}"); + } + } + core.shutdown(); +} + #[test] fn admin_ids_and_log_offsets_respect_the_safe_integer_boundary_before_connecting() { let dir=TempDir::new("admin-integer-boundary"); diff --git a/docs/mobile-port-progress.md b/docs/mobile-port-progress.md index ffb05eb..b39c2ff 100644 --- a/docs/mobile-port-progress.md +++ b/docs/mobile-port-progress.md @@ -4,6 +4,8 @@ ## Возврат к разработке на ПК, 2026-11-26 +Windows, база `d1b611a`: ядро и поля создания/переименования групп считают длину имени в символах Unicode, предел 128. Прошли два теста ядра и один тест форм. В stdio допустимое многобайтное имя дошло до not_connected; превышение предела и перевод строки дали bad_request. Изменение реальных серверных групп не проверялось. + Windows, база `1213468`: административные ID и смещение server_log, порядок каналов и семь числовых свойств server_edit ограничены по эталонному контракту. На границе 2^53−1 проверка stdio дошла до not_connected, а 2^53 отклонено до соединения. Прошли четыре теста ядра и три теста нативного клиента. Серверные квоты и группы на живом сервере не менялись. Windows, база `bff5c33`: проверено поле `channel_codec_quality` в обеих формах. Beta14 вернул 5 после создания и 7 после редактирования того же канала. Значения 11 и −1 остались в форме с ошибкой; отмена изменения на 3 оставила на сервере 7. Прошли три адресных теста, звук не измерялся. diff --git a/native/src/ui/shell/forms.rs b/native/src/ui/shell/forms.rs index 1d16f08..2d6a152 100644 --- a/native/src/ui/shell/forms.rs +++ b/native/src/ui/shell/forms.rs @@ -199,7 +199,8 @@ pub fn form(id:&str, operation:Operation, target:Target, c:&Catalog)->Option fields.push(text(c,"name","admin.name",255,true)), + BookmarkRename | ContactRename | FileFolderCreate => fields.push(text(c,"name","admin.name",255,true)), + GroupRename => fields.push(text(c,"name","admin.name",teamspeach_core::admin::MAX_GROUP_NAME_CHARS,true)), ConfirmPassword => { fields.push(secret(c,"password","admin.password",true)); fields.push(toggle(c,"save","native.action.save",false)); description=c.text("native.profile.password"); } ChannelCreate | ChannelCreateChild | ChannelEdit => { if operation==ChannelCreate { fields.push(target_choice(c,"parent_id","admin.parent")); } @@ -252,7 +253,7 @@ pub fn form(id:&str, operation:Operation, target:Target, c:&Catalog)->Option fields.push(text(c,"message","admin.message",MAX_POKE_BYTES,true)), ClientKickChannel | ClientKickServer => fields.push(text(c,"reason","admin.reason",80,false)), ClientBan | BanCreate => { if operation==BanCreate { fields.extend([text(c,"ip","admin.ip",255,false),text(c,"name","admin.namePattern",255,false),text(c,"uid","admin.uid",255,false)]); } fields.extend([number(c,"duration_s","admin.duration",0,u32::MAX as i64,3600),text(c,"reason","admin.reason",512,false)]); } - ServerGroupCreate | ChannelGroupCreate => fields.extend([text(c,"name","admin.name",255,true),choice(c,"type","admin.type",&[("regular","admin.group"),("template","admin.groups"),("query","admin.clients")])]), + ServerGroupCreate | ChannelGroupCreate => fields.extend([text(c,"name","admin.name",teamspeach_core::admin::MAX_GROUP_NAME_CHARS,true),choice(c,"type","admin.type",&[("regular","admin.group"),("template","admin.groups"),("query","admin.clients")])]), ClientServerGroupAdd | ClientServerGroupRemove | ClientChannelGroupSet => fields.push(target_choice(c,"group_id","admin.group")), PermissionSet | ClientChannelPermissionSet => fields.extend([target_choice(c,"permission_id","clientMenu.permission"),number(c,"value","clientMenu.value",i32::MIN as i64,i32::MAX as i64,0),toggle(c,"negate","admin.menu.negate",false),toggle(c,"skip","admin.menu.skip",false)]), ClientVolume => fields.extend([field(c,"db","clientMenu.volume",FieldKind::SpeakerGain,FieldValue::Decimal(0.0)),toggle(c,"muted","clientMenu.mute",false)]), @@ -334,6 +335,17 @@ pub fn value_text(value:&FieldValue)->String { match value { FieldValue::Text(v) mod tests { use super::*; #[test] + fn group_editors_accept_128_unicode_scalars() { + let c=Catalog::default(); + let name="я".repeat(127)+"\u{1f3b5}"; + for op in [Operation::ServerGroupCreate,Operation::ChannelGroupCreate,Operation::GroupRename] { + let form=form("group",op,Target::application(),&c).unwrap(); + let field=form.fields.iter().find(|f|f.id=="name").unwrap(); + assert_eq!(parse_value(field,&name,&c),Ok(FieldValue::Text(name.clone()))); + assert!(parse_value(field,&format!("{name}x"),&c).is_err()); + } + } + #[test] fn server_quota_and_group_fields_preserve_safe_integer_precision() { let c=Catalog::default(); let f=form("server",Operation::ServerEdit,Target::application(),&c).unwrap();