summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2026-03-07 15:49:44 +0200
committerDirk-Jan C. Binnema <djcb@djcbsoftware.nl>2026-03-07 15:49:44 +0200
commit7cf54aa5dddcd4573685c0cbef929f4e1b5705ed (patch)
treed6ff92a1d7dc63dd8d67b5e77cf37a62a76c7e4a /lib
parent2564720b98bcc713652d1ae16910593b6e9fe256 (diff)
mu/lib: fix some possible quoting issues
Diffstat (limited to 'lib')
-rw-r--r--lib/utils/mu-utils-file.cc5
-rw-r--r--lib/utils/mu-utils.hh18
2 files changed, 17 insertions, 6 deletions
diff --git a/lib/utils/mu-utils-file.cc b/lib/utils/mu-utils-file.cc
index 8f75ff7..56b1c6f 100644
--- a/lib/utils/mu-utils-file.cc
+++ b/lib/utils/mu-utils-file.cc
@@ -370,7 +370,7 @@ expand_path_real(const std::string& str)
int res;
wordexp_t result{};
- res = wordexp(str.c_str(), &result, 0);
+ res = wordexp(str.c_str(), &result, WRDE_NOCMD);
if (res != 0)
return Err(Error::Code::File, "cannot expand {}; err={}", str, res);
else if (auto&n = result.we_wordc; n != 1) {
@@ -395,8 +395,7 @@ Mu::expand_path(const std::string& str)
return res;
// failed... try quoting.
- auto qstr{to_string_gchar(g_shell_quote(str.c_str()))};
- return expand_path_real(qstr);
+ return expand_path_real(shell_quote(str));
}
diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh
index 3e8d3dc..272f28b 100644
--- a/lib/utils/mu-utils.hh
+++ b/lib/utils/mu-utils.hh
@@ -498,7 +498,7 @@ to_string(const T& val)
*
* @return a string_view
*/
-static inline std::string_view
+inline std::string_view
to_string_view(const std::string& s)
{
return std::string_view{s.data(), s.size()};
@@ -511,7 +511,7 @@ to_string_view(const std::string& s)
*
* @return a std::string, empty if gchar was {}
*/
-static inline std::string
+inline std::string
to_string_gchar(gchar*&& str)
{
std::string s(str?str:"");
@@ -525,7 +525,7 @@ to_string_gchar(gchar*&& str)
*
* @return a std::string, empty if gchar was {}
*/
-static inline std::string
+inline std::string
to_string_char(char*&& str)
{
std::string s(str?str:"");
@@ -533,6 +533,18 @@ to_string_char(char*&& str)
return s;
}
+/**
+ * Shell-quote the given string (as per g_shell_quote())
+ *
+ * @param str some string
+ *
+ * @return quoted string
+ */
+inline std::string shell_quote(const std::string& str) {
+ return to_string_gchar(g_shell_quote(str.c_str()));
+}
+
+
/*
* Lexnums are lexicographically sortable string representations of non-negative
* integers. Start with 'f' + length of hex-representation number, followed by