Escape quotes in reply/redact completion message hints
This commit is contained in:
parent
170c5811a3
commit
6aff7ddcbb
2 changed files with 19 additions and 8 deletions
|
@ -137,13 +137,16 @@ def matrix_message_completion_cb(data, completion_item, buffer, completion):
|
|||
if not event_id:
|
||||
continue
|
||||
|
||||
message = line.message
|
||||
# Make sure we'll be able to reliably detect the end of the
|
||||
# quoted snippet
|
||||
message_fmt = line.message.replace("\\", "\\\\") \
|
||||
.replace('"', '\\"')
|
||||
|
||||
if len(message) > REDACTION_COMP_LEN + 2:
|
||||
message = message[:REDACTION_COMP_LEN] + ".."
|
||||
if len(message_fmt) > REDACTION_COMP_LEN + 2:
|
||||
message_fmt = message_fmt[:REDACTION_COMP_LEN] + ".."
|
||||
|
||||
item = ('{event_id}|"{message}"').format(
|
||||
event_id=event_id, message=message
|
||||
event_id=event_id, message=message_fmt
|
||||
)
|
||||
|
||||
W.hook_completion_list_add(
|
||||
|
|
|
@ -182,10 +182,18 @@ def parse_redact_args(args):
|
|||
event_id, rest = (args, "")
|
||||
|
||||
if had_example_text:
|
||||
try:
|
||||
_, _, reason = rest.split("\"", 2)
|
||||
except ValueError:
|
||||
reason = None
|
||||
rest = rest.lstrip()
|
||||
reason = None # until it has been correctly determined
|
||||
if rest[0] == '"':
|
||||
escaped = False
|
||||
for i in range(1, len(rest)):
|
||||
if escaped:
|
||||
escaped = False
|
||||
elif rest[i] == "\\":
|
||||
escaped = True
|
||||
elif rest[i] == '"':
|
||||
reason = rest[i+1:]
|
||||
break
|
||||
else:
|
||||
reason = rest
|
||||
|
||||
|
|
Loading…
Reference in a new issue