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:
|
if not event_id:
|
||||||
continue
|
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:
|
if len(message_fmt) > REDACTION_COMP_LEN + 2:
|
||||||
message = message[:REDACTION_COMP_LEN] + ".."
|
message_fmt = message_fmt[:REDACTION_COMP_LEN] + ".."
|
||||||
|
|
||||||
item = ('{event_id}|"{message}"').format(
|
item = ('{event_id}|"{message}"').format(
|
||||||
event_id=event_id, message=message
|
event_id=event_id, message=message_fmt
|
||||||
)
|
)
|
||||||
|
|
||||||
W.hook_completion_list_add(
|
W.hook_completion_list_add(
|
||||||
|
|
|
@ -182,10 +182,18 @@ def parse_redact_args(args):
|
||||||
event_id, rest = (args, "")
|
event_id, rest = (args, "")
|
||||||
|
|
||||||
if had_example_text:
|
if had_example_text:
|
||||||
try:
|
rest = rest.lstrip()
|
||||||
_, _, reason = rest.split("\"", 2)
|
reason = None # until it has been correctly determined
|
||||||
except ValueError:
|
if rest[0] == '"':
|
||||||
reason = None
|
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:
|
else:
|
||||||
reason = rest
|
reason = rest
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue