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

GUACAMOLE-1632: Fill null chars before last printable char with spaces #523

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/terminal/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ static void guac_terminal_clipboard_append_row(guac_terminal* terminal,

char buffer[1024];
int i = start;
int eol;

guac_terminal_buffer_row* buffer_row =
guac_terminal_buffer_get_row(terminal->buffer, row, 0);
Expand All @@ -296,6 +297,14 @@ static void guac_terminal_clipboard_append_row(guac_terminal* terminal,
if (end < 0 || end > buffer_row->length - 1)
end = buffer_row->length - 1;

/* Get position of last not null char */
for (eol = buffer_row->length; eol > start; eol--) {

if (buffer_row->characters[eol].value != 0)
break;

}

/* Repeatedly convert chunks of terminal buffer rows until entire specified
* region has been appended to clipboard */
while (i <= end) {
Expand All @@ -308,6 +317,10 @@ static void guac_terminal_clipboard_append_row(guac_terminal* terminal,

int codepoint = buffer_row->characters[i].value;

/* Fill empty with spaces if not at end of line */
if (codepoint == 0 && i < eol)
codepoint = GUAC_CHAR_SPACE;

/* Ignore null (blank) characters */
if (codepoint == 0 || codepoint == GUAC_CHAR_CONTINUATION)
continue;
Expand Down
5 changes: 5 additions & 0 deletions src/terminal/terminal/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
*/
#define GUAC_CHAR_CONTINUATION -1

/**
* The ASCII code of space.
*/
#define GUAC_CHAR_SPACE 32

/**
* Terminal attributes, as can be applied to a single character.
*/
Expand Down