From f1d8d0add8e4027293fc588d70447cf559215ba5 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 29 Aug 2012 21:52:17 +0200 Subject: [PATCH] escape whitespaces in filename or buffername completions --- src/buffer_manager.cc | 4 ++-- src/completion.cc | 2 +- src/utils.hh | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 38256ff1..75d0e94c 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -61,7 +61,7 @@ CandidateList BufferManager::complete_buffername(const String& prefix, { const String& name = buffer->name(); if (name.substr(0, real_prefix.length()) == real_prefix) - result.push_back(name); + result.push_back(escape(name)); } // no prefix completion found, check regex matching if (result.empty()) @@ -73,7 +73,7 @@ CandidateList BufferManager::complete_buffername(const String& prefix, { const String& name = buffer->name(); if (boost::regex_search(name.begin(), name.end(), ex)) - result.push_back(name); + result.push_back(escape(name)); } } catch (boost::regex_error& err) {} diff --git a/src/completion.cc b/src/completion.cc index c7d3bbe1..2cbc1468 100644 --- a/src/completion.cc +++ b/src/completion.cc @@ -50,7 +50,7 @@ CandidateList complete_filename(const Context& context, if (entry->d_type == DT_DIR) name += '/'; if (fileprefix.length() != 0 or filename[0] != '.') - result.push_back(name); + result.push_back(escape(name)); } } std::sort(result.begin(), result.end()); diff --git a/src/utils.hh b/src/utils.hh index 6555e320..9892fc92 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -190,6 +190,11 @@ bool operator== (const std::unique_ptr& lhs, T* rhs) return lhs.get() == rhs; } +inline String escape(const String& name) +{ + return name.replace("([ \\t;])", R"(\\\1)"); +} + } #endif // utils_hh_INCLUDED