Skip to content

Commit e05548e

Browse files
committed
Added check to fix unpaired quotes.
1 parent 7279b2b commit e05548e

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/Modules/RemoteTool/RemoteToolFrames.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ SocketFrame::State RemoteToolRequest::ReadInternal(ByteOrderDataStreamReader& st
3030
stream >> m_clientId;
3131
stream >> m_sessionId;
3232
stream >> m_fileData;
33-
StringVector args;
34-
stream >> args;
35-
m_invocation.m_arglist = ParseArgumentList(args);
33+
stream >> m_invocation.m_arglist.m_args;
3634
stream >> m_invocation.m_id.m_toolId;
3735
stream >> m_compression;
36+
m_invocation.m_arglist.TryFixDoubleQuotes();
3837
return stOk;
3938
}
4039

src/ToolExecutionInterface/ArgumentList.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ ArgumentList ParseArgumentList(const StringVector& unparsedArgs, const ArgumentP
4343
std::string current;
4444
bool startedQuote = false;
4545
auto consume = [&current, &args](bool force) {
46-
if (force || !current.empty())
46+
if (!current.empty() && *current.rbegin() == ' ')
47+
current = current.size() == 1 ? "" : current.substr(0, current.size() - 1);
48+
49+
if (force || !current.empty()) {
4750
args.m_args.push_back(std::move(current));
51+
}
4852
current.clear();
4953
};
5054
bool escapedNext = false;
@@ -78,8 +82,13 @@ ArgumentList ParseArgumentList(const StringVector& unparsedArgs, const ArgumentP
7882
}
7983
}
8084
}
81-
consume(false);
85+
if (!startedQuote)
86+
consume(false);
87+
else
88+
current += ' ';
8289
}
90+
91+
consume(false);
8392
return args;
8493
}
8594

@@ -102,4 +111,25 @@ std::string ArgumentList::ToString(const ArgumentStringifySettings& settings) co
102111
return StringUtils::JoinString(escapedArgs, ' ');
103112
}
104113

114+
void ArgumentList::TryFixDoubleQuotes()
115+
{
116+
bool hasCorrectFormat = true;
117+
for (const std::string& arg : m_args) {
118+
if (arg == "\"") {
119+
hasCorrectFormat = false;
120+
break;
121+
} else if (arg.size() >= 2) {
122+
char b = *arg.begin();
123+
char e = *arg.rbegin();
124+
if ((b == '"' && e != '"') || (e == '"' && b != '"')) {
125+
hasCorrectFormat = false;
126+
break;
127+
}
128+
}
129+
}
130+
if (!hasCorrectFormat) {
131+
*this = ParseArgumentList(m_args);
132+
}
133+
}
134+
105135
}

src/ToolExecutionInterface/ArgumentList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct ArgumentList {
3232
StringVector m_args;
3333

3434
std::string ToString(const ArgumentStringifySettings& settings = {}) const noexcept;
35+
void TryFixDoubleQuotes();
3536
};
3637

3738
ArgumentList ParseArgumentList(const StringVector& unparsedArgs, const ArgumentParseSettings& settings = {}) noexcept;

0 commit comments

Comments
 (0)