Skip to content

Commit 308d51f

Browse files
Added logic for handling escape characters at the end for substitution
1 parent 8655289 commit 308d51f

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

Src/runcpp2/Data/StageInfo.cpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,54 @@ namespace
282282
ssLOG_ERROR("INTERNAL ERROR, missing substitution value for \"" << substitution << "\"");
283283
return false;
284284
}
285-
const std::string& currentValue = substitutionMap.at(substitution).at(substituteValueIndex);
285+
286+
std::string currentValue = substitutionMap.at(substitution).at(substituteValueIndex);
287+
288+
//Escape escapes character at the end if any
289+
{
290+
std::vector<char> escapeChars = {'\\'};
291+
#ifdef _WIN32
292+
escapeChars.emplace_back('^');
293+
#endif
294+
if(!currentValue.empty())
295+
{
296+
int currentValIndex = currentValue.size();
297+
while(currentValIndex > 0)
298+
{
299+
--currentValIndex;
300+
bool found = false;
301+
for(int j = 0; j < escapeChars.size(); ++j)
302+
{
303+
if(currentValue[currentValIndex] == escapeChars[j])
304+
{
305+
found = true;
306+
break;
307+
}
308+
}
309+
310+
if(!found)
311+
{
312+
++currentValIndex;
313+
break;
314+
}
315+
}
316+
317+
if(currentValIndex < currentValue.size())
318+
{
319+
const std::string foundEscapes = currentValue.substr(currentValIndex);
320+
std::string newEndEscapes;
321+
//Just repeat the escape characters
322+
for(int j = 0; j < foundEscapes.size(); ++j)
323+
{
324+
newEndEscapes.push_back(foundEscapes[j]);
325+
newEndEscapes.push_back(foundEscapes[j]);
326+
}
327+
328+
currentValue = currentValue.substr(0, currentValIndex) + newEndEscapes;
329+
}
330+
}
331+
}
332+
286333
ssLOG_DEBUG("Replacing \"" << substitution << "\" with \"" << currentValue <<
287334
"\" in \"" << escapedString << "\"");
288335

@@ -436,8 +483,8 @@ bool runcpp2::Data::StageInfo::ConstructCommand(const SubstitutionMap& substitut
436483
{
437484
if(substitutionMap.count(substitutionsInCurrentPart.at(j)) == 0)
438485
{
439-
ssLOG_DEBUG("No substitution found for " << substitutionsInCurrentPart.at(j) << " in " <<
440-
currentRunParts.at(i).CommandPart);
486+
ssLOG_DEBUG("No substitution found for " << substitutionsInCurrentPart.at(j) <<
487+
" in " << currentRunParts.at(i).CommandPart);
441488

442489
ssLOG_DEBUG("Current run part is type repeat, skipping to next");
443490
continue;

mkdocs/docs/TODO.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
- Add initialize submodule option for git
99
- Async/Multi-thread compile and dependencies processing
1010
- Ability to skip DefaultPlatform and DefaultProfile
11-
11+
- Handle escape characters at the end
12+
- To avoid situation like this:
13+
- Substitution string: `-I "{path}"`
14+
- Substitution value: `.\`
15+
- Substituted string: `-I ".\"`
16+
- Where the path contains escape character which escaped the wrapping quotes
1217

1318
## Planned
1419

@@ -76,12 +81,6 @@ endfunction()
7681
print_target_properties(matplot)
7782
-->
7883
- Add the ability to specify different profiles(?)/defines for different source files
79-
- Handle escape characters at the end
80-
- To avoid situation like this:
81-
- Substitution string: -I "{path}"
82-
- Substitution value: .\
83-
- Substituted string: -I ".\"
84-
- Where the path contains escape character which escaped the wrapping quotes
8584
- Use <csignal> to handle potential segfaults
8685
- Use System2 subprocess if no prepend commands to be safer
8786
- Add tests and examples (On Windows as well)

0 commit comments

Comments
 (0)