Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions subprocess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,7 @@ using env_vector_t = std::vector<platform_char_t>;
//--------------------------------------------------------------------
namespace util
{
template <typename R>
inline bool is_ready(std::shared_future<R> const &f)
{
return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready;
}

#ifdef __USING_WINDOWS__
inline void quote_argument(const std::wstring &argument, std::wstring &command_line,
bool force)
{
Expand All @@ -198,7 +193,7 @@ namespace util
//

if (force == false && argument.empty() == false &&
argument.find_first_of(L" \t\n\v\"") == argument.npos) {
argument.find_first_of(L" \t\n\v") == argument.npos) {
command_line.append(argument);
}
else {
Expand Down Expand Up @@ -248,7 +243,6 @@ namespace util
}
}

#ifdef __USING_WINDOWS__
inline std::string get_last_error(DWORD errorMessageID)
{
if (errorMessageID == 0)
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(test_names test_subprocess test_cat test_env test_err_redirection test_exception test_split test_main test_ret_code)
set(test_names test_subprocess test_cat test_double_quotes test_env test_err_redirection test_exception test_split test_main test_ret_code)
set(test_files env_script.sh write_err.sh write_err.txt)


Expand Down
30 changes: 30 additions & 0 deletions test/test_double_quotes.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <subprocess.hpp>

#include <cassert>
#include <string>

namespace sp = subprocess;

// JSON requires the use of double quotes (see: https://json.org/).
// This test verifies proper handling of them.
void test_double_quotes()
{
// A simple JSON object.
const std::string expected{"{\"name\": \"value\"}"};
#ifdef __USING_WINDOWS__
const std::string command{"cmd.exe /c echo "};
#else
const std::string command{"echo "};
#endif
auto p = sp::Popen(command + expected, sp::output{sp::PIPE});
const auto out = p.communicate().first;
std::string result{out.buf.begin(), out.buf.end()};
// The `echo` command appends a newline.
result.erase(result.find_last_not_of(" \n\r\t") + 1);
assert(result == expected);
}

int main() {
test_double_quotes();
return 0;
}