Count Unicode characters consistently in group names
This commit is contained in:
1 parent
d1b611a911
commit
8072e6f1d1
6 files changed
+38
-4
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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"));}},
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user