Also make lists and dicts of strings escape code safe
This commit is contained in:
parent
aac57550c9
commit
902373ed20
@ -167,7 +167,7 @@ def generate_completions_for_kitty() -> None:
|
||||
|
||||
# rc command wrappers {{{
|
||||
json_field_types: Dict[str, str] = {
|
||||
'bool': 'bool', 'str': 'escaped_string', 'list.str': '[]string', 'dict.str': 'map[string]string', 'float': 'float64', 'int': 'int',
|
||||
'bool': 'bool', 'str': 'escaped_string', 'list.str': '[]escaped_string', 'dict.str': 'map[escaped_string]escaped_string', 'float': 'float64', 'int': 'int',
|
||||
'scroll_amount': 'any', 'spacing': 'any', 'colors': 'any',
|
||||
}
|
||||
|
||||
@ -239,6 +239,10 @@ def go_code_for_remote_command(name: str, cmd: RemoteCommand, template: str) ->
|
||||
used_options.add(oq)
|
||||
if field.field_type == 'str':
|
||||
jc.append(f'payload.{field.struct_field_name} = escaped_string(options_{name}.{o.go_var_name})')
|
||||
elif field.field_type == 'list.str':
|
||||
jc.append(f'payload.{field.struct_field_name} = escape_list_of_strings(options_{name}.{o.go_var_name})')
|
||||
elif field.field_type == 'dict.str':
|
||||
jc.append(f'payload.{field.struct_field_name} = escape_dict_of_strings(options_{name}.{o.go_var_name})')
|
||||
else:
|
||||
jc.append(f'payload.{field.struct_field_name} = options_{name}.{o.go_var_name}')
|
||||
elif field.field in handled_fields:
|
||||
|
||||
@ -233,7 +233,7 @@ class ArgsHandling:
|
||||
jt = field_types[jf]
|
||||
if self.first_rest:
|
||||
yield f'payload.{self.first_rest[0].capitalize()} = escaped_string(args[0])'
|
||||
yield f'payload.{self.first_rest[1].capitalize()} = args[1:]'
|
||||
yield f'payload.{self.first_rest[1].capitalize()} = escape_list_of_strings(args[1:])'
|
||||
handled_fields.add(self.first_rest[0])
|
||||
handled_fields.add(self.first_rest[1])
|
||||
return
|
||||
@ -250,7 +250,7 @@ class ArgsHandling:
|
||||
yield 'if err != nil { return err }'
|
||||
return
|
||||
if jt == 'list.str':
|
||||
yield f'{dest} = args'
|
||||
yield f'{dest} = escape_list_of_strings(args)'
|
||||
return
|
||||
if jt == 'str':
|
||||
if c == 1:
|
||||
|
||||
@ -6,14 +6,14 @@ import (
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
|
||||
func parse_key_val_args(args []string) map[string]string {
|
||||
ans := make(map[string]string, len(args))
|
||||
func parse_key_val_args(args []string) map[escaped_string]escaped_string {
|
||||
ans := make(map[escaped_string]escaped_string, len(args))
|
||||
for _, arg := range args {
|
||||
key, value, found := utils.Cut(arg, "=")
|
||||
if found {
|
||||
ans[key] = value
|
||||
ans[escaped_string(key)] = escaped_string(value)
|
||||
} else {
|
||||
ans[key+"="] = ""
|
||||
ans[escaped_string(key+"=")] = ""
|
||||
}
|
||||
}
|
||||
return ans
|
||||
|
||||
@ -46,6 +46,22 @@ func expand_ansi_c_escapes_in_args(args ...string) (escaped_string, error) {
|
||||
return escaped_string(strings.Join(args, " ")), nil
|
||||
}
|
||||
|
||||
func escape_list_of_strings(args []string) []escaped_string {
|
||||
ans := make([]escaped_string, len(args))
|
||||
for i, x := range args {
|
||||
ans[i] = escaped_string(x)
|
||||
}
|
||||
return ans
|
||||
}
|
||||
|
||||
func escape_dict_of_strings(args map[string]string) map[escaped_string]escaped_string {
|
||||
ans := make(map[escaped_string]escaped_string, len(args))
|
||||
for k, v := range args {
|
||||
ans[escaped_string(k)] = escaped_string(v)
|
||||
}
|
||||
return ans
|
||||
}
|
||||
|
||||
func set_payload_string_field(io_data *rc_io_data, field, data string) {
|
||||
payload_interface := reflect.ValueOf(&io_data.rc.Payload).Elem()
|
||||
struct_in_interface := reflect.New(payload_interface.Elem().Type()).Elem()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user