mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Plain stravis() because it will mangle UTF-8 characters, so add
utf8_stravis() which calls our existing utf8_strvis() and use it instead
This commit is contained in:
		@@ -162,7 +162,7 @@ args_print(struct args *args)
 | 
			
		||||
		flags = VIS_OCTAL|VIS_TAB|VIS_NL;
 | 
			
		||||
		if (entry->value[strcspn(entry->value, quoted)] != '\0')
 | 
			
		||||
			flags |= VIS_DQ;
 | 
			
		||||
		stravis(&escaped, entry->value, flags);
 | 
			
		||||
		utf8_stravis(&escaped, entry->value, flags);
 | 
			
		||||
		if (flags & VIS_DQ)
 | 
			
		||||
			args_print_add(&buf, &len, "\"%s\"", escaped);
 | 
			
		||||
		else
 | 
			
		||||
@@ -178,7 +178,7 @@ args_print(struct args *args)
 | 
			
		||||
		flags = VIS_OCTAL|VIS_TAB|VIS_NL;
 | 
			
		||||
		if (args->argv[i][strcspn(args->argv[i], quoted)] != '\0')
 | 
			
		||||
			flags |= VIS_DQ;
 | 
			
		||||
		stravis(&escaped, args->argv[i], flags);
 | 
			
		||||
		utf8_stravis(&escaped, args->argv[i], flags);
 | 
			
		||||
		if (flags & VIS_DQ)
 | 
			
		||||
			args_print_add(&buf, &len, "\"%s\"", escaped);
 | 
			
		||||
		else
 | 
			
		||||
 
 | 
			
		||||
@@ -105,7 +105,7 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
 | 
			
		||||
	if (args_has(self->args, 'v'))
 | 
			
		||||
		cmdq_print(item, "%s", value);
 | 
			
		||||
	else if (options_isstring(o)) {
 | 
			
		||||
		stravis(&escaped, value, VIS_OCTAL|VIS_TAB|VIS_NL|VIS_DQ);
 | 
			
		||||
		utf8_stravis(&escaped, value, VIS_OCTAL|VIS_TAB|VIS_NL|VIS_DQ);
 | 
			
		||||
		cmdq_print(item, "%s \"%s\"", name, escaped);
 | 
			
		||||
		free(escaped);
 | 
			
		||||
	} else
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								tmux.h
									
									
									
									
									
								
							@@ -2295,6 +2295,7 @@ enum utf8_state	 utf8_append(struct utf8_data *, u_char);
 | 
			
		||||
enum utf8_state	 utf8_combine(const struct utf8_data *, wchar_t *);
 | 
			
		||||
enum utf8_state	 utf8_split(wchar_t, struct utf8_data *);
 | 
			
		||||
int		 utf8_strvis(char *, const char *, size_t, int);
 | 
			
		||||
int		 utf8_stravis(char **, const char *, int);
 | 
			
		||||
char		*utf8_sanitize(const char *);
 | 
			
		||||
size_t		 utf8_strlen(const struct utf8_data *);
 | 
			
		||||
u_int		 utf8_strwidth(const struct utf8_data *, ssize_t);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										14
									
								
								utf8.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								utf8.c
									
									
									
									
									
								
							@@ -193,6 +193,20 @@ utf8_strvis(char *dst, const char *src, size_t len, int flag)
 | 
			
		||||
	return (dst - start);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Same as utf8_strvis but allocate the buffer. */
 | 
			
		||||
int
 | 
			
		||||
utf8_stravis(char **dst, const char *src, int flag)
 | 
			
		||||
{
 | 
			
		||||
	char	*buf;
 | 
			
		||||
	int	 len;
 | 
			
		||||
 | 
			
		||||
	buf = xreallocarray(NULL, 4, strlen(src) + 1);
 | 
			
		||||
	len = utf8_strvis(buf, src, strlen(src), flag);
 | 
			
		||||
 | 
			
		||||
	*dst = xrealloc(buf, len + 1);
 | 
			
		||||
	return (len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Sanitize a string, changing any UTF-8 characters to '_'. Caller should free
 | 
			
		||||
 * the returned string. Anything not valid printable ASCII or UTF-8 is
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user