diff options
author | Peter Rice <peter@peterrice.xyz> | 2019-08-06 21:41:38 -0400 |
---|---|---|
committer | Peter Rice <peter@peterrice.xyz> | 2019-08-06 21:41:38 -0400 |
commit | e1e220c975e50cc159197ad9409278719e671ff7 (patch) | |
tree | 94bc8231b66f65b7d34d37cacdeee7116e4efbf9 | |
parent | 2ff23ed71912a958f0ccd729d2a088aa660a71ea (diff) |
Escape single quotes in filenames
-rw-r--r-- | src/screens/lyrics.cpp | 3 | ||||
-rw-r--r-- | src/utility/string.cpp | 12 | ||||
-rw-r--r-- | src/utility/string.h | 2 |
3 files changed, 16 insertions, 1 deletions
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 |