Normalize Turnstile env values
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 48s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 48s
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
require('dotenv').config();
|
||||
|
||||
const firstEnvValue = (...values) => values.find((value) => typeof value === 'string' && value.trim())?.trim() || '';
|
||||
const TURNSTILE_KEY_MATCH = /[0-9]x[0-9A-Za-z_-]{20,}/;
|
||||
|
||||
const normalizeTurnstileValue = (value) => {
|
||||
if (typeof value !== 'string') return '';
|
||||
|
||||
const trimmedValue = value.trim();
|
||||
const keyMatch = trimmedValue.match(TURNSTILE_KEY_MATCH);
|
||||
if (keyMatch) return keyMatch[0];
|
||||
|
||||
return trimmedValue.replace(/^[\s"'`{[]+|[\s"'`}\]]+$/g, '');
|
||||
};
|
||||
|
||||
const firstEnvValue = (...values) => values
|
||||
.map(normalizeTurnstileValue)
|
||||
.find(Boolean) || '';
|
||||
|
||||
const TURNSTILE_SITE_KEY = firstEnvValue(
|
||||
process.env.TURNSTILE_SITE_KEY,
|
||||
|
||||
Reference in New Issue
Block a user