Skip to content

Commit 60fd590

Browse files
committed
fix(build): handle Unicode warning quotes safely
2 parents 6834912 + 854bcb2 commit 60fd590

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

src/build/BuildStyle.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,27 @@ namespace vix::cli::build
183183
if (ns != std::string::npos)
184184
value = value.substr(ns + 2);
185185

186-
if (!value.empty() && value.front() == '\'' && value.back() == '\'')
186+
if (value.size() >= 2 &&
187+
value.front() == '\'' &&
188+
value.back() == '\'')
189+
{
187190
value = value.substr(1, value.size() - 2);
191+
}
192+
193+
const std::string leftQuote = "";
194+
const std::string rightQuote = "";
188195

189-
if (!value.empty() && value.front() == '' && value.back() == '')
190-
value = value.substr(3, value.size() > 6 ? value.size() - 6 : value.size());
196+
if (value.size() >= leftQuote.size() + rightQuote.size() &&
197+
value.rfind(leftQuote, 0) == 0 &&
198+
value.compare(
199+
value.size() - rightQuote.size(),
200+
rightQuote.size(),
201+
rightQuote) == 0)
202+
{
203+
value = value.substr(
204+
leftQuote.size(),
205+
value.size() - leftQuote.size() - rightQuote.size());
206+
}
191207

192208
return trim_copy(value);
193209
}
@@ -853,8 +869,8 @@ namespace vix::cli::build
853869
}
854870

855871
if (cleanMessage.find("shadows a previous local") != std::string::npos ||
856-
cleanMessage.find("declaration of") != std::string::npos &&
857-
cleanMessage.find("shadows") != std::string::npos)
872+
(cleanMessage.find("declaration of") != std::string::npos &&
873+
cleanMessage.find("shadows") != std::string::npos))
858874
{
859875
warning.kind = BuildWarningKind::ShadowedVariable;
860876
warning.symbol = shorten_cpp_signature(quoted);

0 commit comments

Comments
 (0)