Skip to content
Snippets Groups Projects
Commit 00aa37c6 authored by Matt Mackall's avatar Matt Mackall
Browse files

ui: try to handle $$ more robustly in prompts (issue4970)

parent d9e3ebe5
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@
import getpass
import inspect
import os
import re
import socket
import sys
import tempfile
......@@ -764,4 +765,11 @@
This returns tuple "(message, choices)", and "choices" is the
list of tuple "(response character, text without &)".
>>> ui.extractchoices("awake? $$ &Yes $$ &No")
('awake? ', [('y', 'Yes'), ('n', 'No')])
>>> ui.extractchoices("line\\nbreak? $$ &Yes $$ &No")
('line\\nbreak? ', [('y', 'Yes'), ('n', 'No')])
>>> ui.extractchoices("want lots of $$money$$?$$Ye&s$$N&o")
('want lots of $$money$$?', [('s', 'Yes'), ('o', 'No')])
"""
......@@ -767,7 +775,13 @@
"""
parts = prompt.split('$$')
msg = parts[0].rstrip(' ')
choices = [p.strip(' ') for p in parts[1:]]
# Sadly, the prompt string may have been built with a filename
# containing "$$" so let's try to find the first valid-looking
# prompt to start parsing. Sadly, we also can't rely on
# choices containing spaces, ASCII, or basically anything
# except an ampersand followed by a character.
m = re.match(r'(?s)(.+?)\$\$([^\$]*&[^ \$].*)', prompt)
msg = m.group(1)
choices = [p.strip(' ') for p in m.group(2).split('$$')]
return (msg,
[(s[s.index('&') + 1].lower(), s.replace('&', '', 1))
for s in choices])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment