@@ -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 ;
0 commit comments