Trim whitespace and quotes in variable substitution

This commit is contained in:
Christiaan Goossens 2024-06-15 13:50:06 +02:00 committed by GitHub
parent 861a3d2091
commit c055d6a1ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -59,7 +59,10 @@ export function substituteEnvironmentVars(str) {
const cachedVars = getCachedEnvironmentVars();
cachedVars.forEach(([key, value]) => {
if (key.startsWith(homepageVarPrefix)) {
result = result.replaceAll(`{{${key}}}`, value);
// Remove whitespace and quotes on edges of the string
// Leave quotes in the middle of the string in
const sanitizedValue = value.replace(/^[\s"']+|[\s"']+$/g, '');
result = result.replaceAll(`{{${key}}}`, sanitizedValue);
} else if (key.startsWith(homepageFilePrefix)) {
const filename = value;
const fileContents = readFileSync(filename, "utf8");