UNPKG

spanwright

Version:

CLI tool to generate Cloud Spanner E2E testing framework projects with Go database tools and Playwright browser automation

46 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SAFE_PATTERNS = void 0; exports.escapeForTemplate = escapeForTemplate; exports.validateTemplateInput = validateTemplateInput; exports.simpleTemplateReplace = simpleTemplateReplace; const errors_1 = require("./errors"); const constants_1 = require("./constants"); Object.defineProperty(exports, "SAFE_PATTERNS", { enumerable: true, get: function () { return constants_1.VALIDATION_PATTERNS; } }); // Basic template security utilities /** * Basic input escaping for template replacement */ function escapeForTemplate(input) { // Basic validation if (!constants_1.VALIDATION_PATTERNS.GENERIC_IDENTIFIER.test(input)) { throw new errors_1.SecurityError(`Invalid characters in input: ${input}`, input); } // Simple escaping return input; } /** * Basic template input validation */ function validateTemplateInput(input, inputType = 'GENERIC_IDENTIFIER') { const pattern = constants_1.VALIDATION_PATTERNS[inputType]; if (!pattern.test(input)) { throw new errors_1.SecurityError(`Input validation failed for ${inputType}: ${input}`, input); } } /** * Simple template replacement */ function simpleTemplateReplace(content, replacements) { let result = content; for (const [search, replace] of Object.entries(replacements)) { // Escape the search pattern for regex const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // Validate the replacement value validateTemplateInput(replace); // Perform the replacement result = result.replace(new RegExp(escapedSearch, 'g'), replace); } return result; } //# sourceMappingURL=template-security.js.map