diff options
author | David Shah <dave@ds0.me> | 2020-04-24 16:41:13 +0100 |
---|---|---|
committer | David Shah <dave@ds0.me> | 2020-04-24 16:41:13 +0100 |
commit | 5024fc06905476d9bf49c28350ae9fef83953519 (patch) | |
tree | b3e6be9069327b979feb08c028b0ce91238bb676 | |
parent | fd099cef52a2ef7a83bc3f68d6e7ed736516978e (diff) | |
download | nextpnr-5024fc06905476d9bf49c28350ae9fef83953519.tar.gz nextpnr-5024fc06905476d9bf49c28350ae9fef83953519.tar.bz2 nextpnr-5024fc06905476d9bf49c28350ae9fef83953519.zip |
python: Escape strings for autocomplete
Signed-off-by: David Shah <dave@ds0.me>
-rw-r--r-- | 3rdparty/python-console/modified/pyinterpreter.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/3rdparty/python-console/modified/pyinterpreter.cc b/3rdparty/python-console/modified/pyinterpreter.cc index 89c9b88c..958049b9 100644 --- a/3rdparty/python-console/modified/pyinterpreter.cc +++ b/3rdparty/python-console/modified/pyinterpreter.cc @@ -82,7 +82,13 @@ const std::list<std::string> &pyinterpreter_suggest(const std::string &hint) PyEval_AcquireThread(m_threadState); m_suggestions.clear(); int i = 0; - std::string command = string_format("sys.completer.complete('%s', %d)\n", hint.c_str(), i); + std::string escaped; + for (char c : hint) { + if (c == '\'' || c == '\\') + escaped += '\\'; + escaped += c; + } + std::string command = string_format("sys.completer.complete('%s', %d)\n", escaped.c_str(), i); std::string res; do { PyObject *py_result; @@ -94,7 +100,7 @@ const std::list<std::string> &pyinterpreter_suggest(const std::string &hint) res = redirector_take_output(m_threadState); ++i; - command = string_format("sys.completer.complete('%s', %d)\n", hint.c_str(), i); + command = string_format("sys.completer.complete('%s', %d)\n", escaped.c_str(), i); if (res.size()) { // throw away the newline res = res.substr(1, res.size() - 3); |