Skip to content

Commit

Permalink
fix: wide-char drop on resize to 1 and invalid session names (#2082)
Browse files Browse the repository at this point in the history
* fix: deny invalid session name

* fix: `zellij attach --create SESSION_NAME` check session name

* fix: drain_until(1) discard widechar

* style(grid): add comment explaining the change

Co-authored-by: Aram Drevekenin <aram@poor.dev>
  • Loading branch information
wlsnx and imsnif authored Jan 13, 2023
1 parent 223b7a1 commit f07c1af
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ pub(crate) fn start_client(opts: CliArgs) {
};
let os_input = get_os_input(get_client_os_input);

let start_client_plan = |session_name: std::string::String| {
assert_session_ne(&session_name);
};

if let Some(Command::Sessions(Sessions::Attach {
session_name,
create,
Expand All @@ -339,6 +343,9 @@ pub(crate) fn start_client(opts: CliArgs) {
let client = if let Some(idx) = index {
attach_with_session_index(config_options.clone(), idx, create)
} else {
if create {
session_name.clone().map(start_client_plan);
}
attach_with_session_name(session_name, config_options.clone(), create)
};

Expand All @@ -363,10 +370,6 @@ pub(crate) fn start_client(opts: CliArgs) {
attach_layout,
);
} else {
let start_client_plan = |session_name: std::string::String| {
assert_session_ne(&session_name);
};

if let Some(session_name) = opts.session.clone() {
start_client_plan(session_name.clone());
start_client_impl(
Expand Down
8 changes: 8 additions & 0 deletions src/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ pub(crate) fn assert_session_ne(name: &str) {
eprintln!("Session name cannot be empty. Please provide a specific session name.");
process::exit(1);
}
if name == "." || name == ".." {
eprintln!("Invalid session name: \"{}\".", name);
process::exit(1);
}
if name.contains('/') {
eprintln!("Session name cannot contains '/'.");
process::exit(1);
}

match session_exists(name) {
Ok(result) if !result => return,
Expand Down
4 changes: 3 additions & 1 deletion zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3218,7 +3218,9 @@ impl Row {
let mut drained_part: VecDeque<TerminalCharacter> = VecDeque::new();
let mut drained_part_len = 0;
while let Some(next_character) = self.columns.remove(0) {
if drained_part_len + next_character.width <= x {
// drained_part_len == 0 here is so that if the grid is resized
// to a size of 1, we won't drop wide characters
if drained_part_len + next_character.width <= x || drained_part_len == 0 {
drained_part.push_back(next_character);
drained_part_len += next_character.width;
} else {
Expand Down

0 comments on commit f07c1af

Please sign in to comment.