From e1e220c975e50cc159197ad9409278719e671ff7 Mon Sep 17 00:00:00 2001 From: Peter Rice Date: Tue, 6 Aug 2019 21:41:38 -0400 Subject: Escape single quotes in filenames --- src/screens/lyrics.cpp | 3 ++- src/utility/string.cpp | 12 ++++++++++++ src/utility/string.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/screens/lyrics.cpp b/src/screens/lyrics.cpp index dacfa7f4..0a89bd8e 100644 --- a/src/screens/lyrics.cpp +++ b/src/screens/lyrics.cpp @@ -326,6 +326,7 @@ void Lyrics::edit() GNUC_UNUSED int res; std::string command; std::string filename = lyricsFilename(m_song); + escapeSingleQuotes(filename); if (Config.use_console_editor) { command = Config.external_editor + " '" + filename + "'"; @@ -337,7 +338,7 @@ void Lyrics::edit() else { command = "nohup " + Config.external_editor - + " \"" + filename + "\" > /dev/null 2>&1 &"; + + " '" + filename + "' > /dev/null 2>&1 &"; res = system(command.c_str()); } } diff --git a/src/utility/string.cpp b/src/utility/string.cpp index 837a6b7a..f82e6be7 100644 --- a/src/utility/string.cpp +++ b/src/utility/string.cpp @@ -96,3 +96,15 @@ void removeInvalidCharsFromFilename(std::string &filename, bool win32_compatible } } } + +void escapeSingleQuotes(std::string &filename) +{ + for (size_t i = 0; i < filename.length(); ++i) + { + if (filename[i] == '\'') + { + filename.replace(i, 1, "'\\''"); + i += 3; + } + } +} diff --git a/src/utility/string.h b/src/utility/string.h index f9910f4d..41616756 100644 --- a/src/utility/string.h +++ b/src/utility/string.h @@ -60,4 +60,6 @@ std::string getEnclosedString(const std::string &s, char a, char b, size_t *pos) void removeInvalidCharsFromFilename(std::string &filename, bool win32_compatible); +void escapeSingleQuotes(std::string &filename); + #endif // NCMPCPP_UTILITY_STRING_H -- cgit v1.2.3