Skip to content

Commit 31e8b02

Browse files
committed
chore: improves input parsing
1 parent 08acfdb commit 31e8b02

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

scripts/update_translations.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,27 @@ function getCliParameters() {
261261
parameters[key.replace('--', '')] = value || true;
262262
});
263263

264+
// Sanitize ci validation input
265+
const ciValidationParam = parameters['ci-validation'];
266+
if (ciValidationParam && (typeof ciValidationParam !== 'boolean')) {
267+
console.warn(`❌ Must not offer any value for --ci-validation.`);
268+
process.exit(1);
269+
}
270+
271+
// Sanitize languages input, removing empty strings and using the default value if none provided
272+
const strictLanguagesParam = parameters['strict-languages'];
273+
if (strictLanguagesParam && (typeof strictLanguagesParam !== 'string')) {
274+
console.warn(`❌ Invalid value for --strict-languages. Usage: node update_translations.js --ci-validation --strict-languages=ru-ru,da`);
275+
process.exit(1);
276+
}
277+
const sanitizedLanguagesInput = strictLanguagesParam?.split(',').filter((lang) => lang) || [];
278+
const treatedLanguagesParam = sanitizedLanguagesInput?.length
279+
? sanitizedLanguagesInput
280+
: mandatoryTranslations;
281+
264282
return {
265-
isCiValidationRun: parameters['ci-validation'] || false,
266-
strictLanguages: parameters['strict-languages']?.split(',') || mandatoryTranslations,
283+
isCiValidationRun: ciValidationParam || false,
284+
strictLanguages: treatedLanguagesParam,
267285
}
268286
}
269287

0 commit comments

Comments
 (0)