@@ -43,6 +43,8 @@ class FileServeTests : public CPPUNIT_NS::TestFixture
4343
4444 void preProcessedFileSubstitution (const std::string& testname,
4545 std::unordered_map<std::string, std::string> variables);
46+ // helper for replacements with the empty map
47+ std::string& replaceOrKeep (std::string& str, const std::string& from, const std::string& to);
4648};
4749
4850void FileServeTests::testUIDefaults ()
@@ -391,30 +393,41 @@ void FileServeTests::preProcessedFileSubstitution(
391393
392394 const std::string recon = ppf.substitute (variables);
393395
394- Poco::replaceInPlace (orig, std::string (" %ACCESS_TOKEN%" ), variables[" ACCESS_TOKEN" ]);
395- Poco::replaceInPlace (orig, std::string (" %ACCESS_TOKEN_TTL%" ),
396+ replaceOrKeep (orig, std::string (" %ACCESS_TOKEN%" ), variables[" ACCESS_TOKEN" ]);
397+ replaceOrKeep (orig, std::string (" %ACCESS_TOKEN_TTL%" ),
396398 variables[" ACCESS_TOKEN_TTL" ]);
397- Poco::replaceInPlace (orig, std::string (" %ACCESS_HEADER%" ), variables[" ACCESS_HEADER" ]);
398- Poco::replaceInPlace (orig, std::string (" %UI_DEFAULTS%" ), variables[" UI_DEFAULTS" ]);
399- Poco::replaceInPlace (orig, std::string (" <!--%CSS_VARIABLES%-->" ),
399+ replaceOrKeep (orig, std::string (" %ACCESS_HEADER%" ), variables[" ACCESS_HEADER" ]);
400+ replaceOrKeep (orig, std::string (" %UI_DEFAULTS%" ), variables[" UI_DEFAULTS" ]);
401+ replaceOrKeep (orig, std::string (" <!--%CSS_VARIABLES%-->" ),
400402 variables[" CSS_VARIABLES" ]);
401- Poco::replaceInPlace (orig, std::string (" %POSTMESSAGE_ORIGIN%" ),
403+ replaceOrKeep (orig, std::string (" %POSTMESSAGE_ORIGIN%" ),
402404 variables[" POSTMESSAGE_ORIGIN" ]);
403- Poco::replaceInPlace (orig, std::string (" %BRANDING_THEME%" ),
405+ replaceOrKeep (orig, std::string (" %BRANDING_THEME%" ),
404406 variables[" BRANDING_THEME" ]);
405- Poco::replaceInPlace (orig, std::string (" <!--%BRANDING_JS%-->" ),
407+ replaceOrKeep (orig, std::string (" <!--%BRANDING_JS%-->" ),
406408 variables[" BRANDING_JS" ]);
407- Poco::replaceInPlace (orig, std::string (" %FOOTER%" ), variables[" FOOTER" ]);
408- Poco::replaceInPlace (orig, std::string (" %CHECK_FILE_INFO_OVERRIDE%" ),
409+ replaceOrKeep (orig, std::string (" %FOOTER%" ), variables[" FOOTER" ]);
410+ replaceOrKeep (orig, std::string (" %CHECK_FILE_INFO_OVERRIDE%" ),
409411 variables[" CHECK_FILE_INFO_OVERRIDE" ]);
410- Poco::replaceInPlace (orig, std::string (" %BUYPRODUCT_URL%" ),
412+ replaceOrKeep (orig, std::string (" %BUYPRODUCT_URL%" ),
411413 variables[" BUYPRODUCT_URL" ]);
412414
413415 LOK_ASSERT_EQUAL (orig, recon);
414416 }
415417 }
416418}
417419
420+ // Replace each occurence of from in str to to except if to is the empty string
421+ std::string& FileServeTests::replaceOrKeep (std::string& str, const std::string& from,
422+ const std::string& to)
423+ {
424+ if (to.empty ())
425+ {
426+ return str;
427+ }
428+ return Poco::replaceInPlace (str, from, to);
429+ }
430+
418431void FileServeTests::testPreProcessedFileSubstitution ()
419432{
420433 constexpr auto testname = __func__;
0 commit comments