Browse Source

Executable path escaping improvement

merge-requests/365/head
eidheim 10 years ago
parent
commit
d19fbd9cc7
  1. 8
      src/cmake.cc
  2. 20
      src/filesystem.cc
  3. 3
      src/filesystem.h
  4. 26
      src/window.cc
  5. 1
      src/window.h

8
src/cmake.cc

@ -115,8 +115,8 @@ bool CMake::create_compile_commands(const boost::filesystem::path &project_path)
return false;
auto compile_commands_path=default_build_path/"compile_commands.json";
Dialog::Message message("Creating "+compile_commands_path.string());
auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" \""+
project_path.string()+"\" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", default_build_path);
auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" "+
filesystem::escape(project_path)+" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", default_build_path);
message.hide();
if(exit_status==EXIT_SUCCESS) {
#ifdef _WIN32 //Temporary fix to MSYS2's libclang
@ -145,8 +145,8 @@ bool CMake::create_debug_build(const boost::filesystem::path &project_path) {
std::unique_ptr<Dialog::Message> message;
if(!boost::filesystem::exists(debug_build_path/"CMakeCache.txt"))
message=std::unique_ptr<Dialog::Message>(new Dialog::Message("Creating debug build"));
auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" \""+
project_path.string()+"\" -DCMAKE_BUILD_TYPE=Debug", debug_build_path);
auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" "+
filesystem::escape(project_path)+" -DCMAKE_BUILD_TYPE=Debug", debug_build_path);
if(message)
message->hide();
if(exit_status==EXIT_SUCCESS)

20
src/filesystem.cc

@ -135,3 +135,23 @@ bool filesystem::write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> bu
}
return false;
}
std::string filesystem::escape(const std::string &path) {
auto escaped=path;
size_t pos=0;
while((pos=escaped.find(' ', pos))!=std::string::npos) {
escaped.replace(pos, 1, "\\ ");
pos+=2;
}
return escaped;
}
std::string filesystem::unescape(const std::string &path) {
auto escaped=path;
size_t pos=0;
while((pos=escaped.find("\\ ", pos))!=std::string::npos) {
escaped.replace(pos, 2, " ");
pos+=1;
}
return escaped;
}

3
src/filesystem.h

@ -25,5 +25,8 @@ public:
static bool write(const std::string &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer);
static bool write(const boost::filesystem::path &path, Glib::RefPtr<Gtk::TextBuffer> text_buffer) { return write(path.string(), text_buffer); }
static std::string escape(const std::string &path);
static std::string escape(const boost::filesystem::path &path) { return escape(path.string()); };
static std::string unescape(const std::string &path);
};
#endif // JUCI_FILESYSTEM_H_

26
src/window.cc

@ -178,21 +178,6 @@ std::unique_ptr<CMake> Window::get_cmake() {
return std::unique_ptr<CMake>(new CMake(path));
}
void Window::escape_executable(std::string &executable) {
bool backslash=false;
for(auto it=executable.begin();it!=executable.end();) {
if(*it=='\\' && !backslash)
backslash=true;
else if(backslash)
backslash=false;
else if(*it==' ') {
it=executable.insert(it, '\\');
it++;
}
it++;
}
}
void Window::configure() {
Config::get().load();
auto style_context = Gtk::StyleContext::create();
@ -604,10 +589,11 @@ void Window::set_menu_actions() {
size_t pos=executable.find(project_path.string());
if(pos!=std::string::npos)
executable.replace(pos, project_path.string().size(), default_build_path.string());
escape_executable(executable);
}
run_arguments=executable;
run_arguments=filesystem::escape(executable);
}
else
run_arguments=cmake.project_path.string();
}
entry_box.clear();
@ -663,7 +649,7 @@ void Window::set_menu_actions() {
size_t pos=command.find(project_path.string());
if(pos!=std::string::npos)
command.replace(pos, project_path.string().size(), default_build_path.string());
escape_executable(command);
command=filesystem::escape(command);
}
compiling=true;
@ -775,7 +761,7 @@ void Window::set_menu_actions() {
size_t pos=command.find(project_path.string());
if(pos!=std::string::npos)
command.replace(pos, project_path.string().size(), debug_build_path.string());
escape_executable(command);
command=filesystem::escape(command);
//}
auto breakpoints=std::make_shared<std::vector<std::pair<boost::filesystem::path, int> > >();
@ -796,7 +782,7 @@ void Window::set_menu_actions() {
if(exit_status!=EXIT_SUCCESS)
debugging=false;
else {
Debug::get().start(breakpoints, command, debug_build_path, [this, command](int exit_status){
Debug::get().start(breakpoints, filesystem::unescape(command), debug_build_path, [this, command](int exit_status){
debugging=false;
Terminal::get().async_print(command+" returned: "+std::to_string(exit_status)+'\n');
}, [this](const std::string &status) {

1
src/window.h

@ -47,7 +47,6 @@ private:
Glib::Dispatcher debug_update_status;
std::unique_ptr<CMake> get_cmake();
void escape_executable(std::string &executable);
std::unordered_map<std::string, std::string> project_run_arguments;
std::unordered_map<std::string, std::string> debug_run_arguments;

Loading…
Cancel
Save