ci: avoid regex literals in typhon Jenkinsfile

This commit is contained in:
Brad Stein 2026-05-16 15:46:38 -03:00
parent b094123518
commit d0143bfc71

29
Jenkinsfile vendored
View File

@ -139,11 +139,11 @@ const sourceExts = new Set(['.ts', '.js', '.cjs', '.mjs', '.sh']);
function unescapeXml(value) { function unescapeXml(value) {
return String(value || '') return String(value || '')
.replace(/"/g, '"') .split('"').join('"')
.replace(/'/g, "'") .split(''').join("'")
.replace(/&lt;/g, '<') .split('&lt;').join('<')
.replace(/&gt;/g, '>') .split('&gt;').join('>')
.replace(/&amp;/g, '&'); .split('&amp;').join('&');
} }
function attr(attrs, name) { function attr(attrs, name) {
@ -174,7 +174,7 @@ function collectSourceFiles(rootDir) {
} }
function categoryForClassname(classname) { function categoryForClassname(classname) {
const normalized = String(classname || '').replace(/\\/g, '/'); const normalized = String(classname || '').split('\\').join('/');
const relative = normalized.includes('/tests/') const relative = normalized.includes('/tests/')
? normalized.slice(normalized.indexOf('/tests/') + '/tests/'.length) ? normalized.slice(normalized.indexOf('/tests/') + '/tests/'.length)
: (normalized.startsWith('tests/') ? normalized.slice('tests/'.length) : normalized); : (normalized.startsWith('tests/') ? normalized.slice('tests/'.length) : normalized);
@ -187,7 +187,7 @@ function categoryForClassname(classname) {
function parseTestCases(junit) { function parseTestCases(junit) {
const cases = []; const cases = [];
const re = /<testcase\b([^>]*)>([\s\S]*?)<\/testcase>|<testcase\b([^>]*)\/>/g; const re = new RegExp('<testcase\\b([^>]*)>([\\s\\S]*?)</testcase>|<testcase\\b([^>]*)/>', 'g');
let match; let match;
while ((match = re.exec(junit)) !== null) { while ((match = re.exec(junit)) !== null) {
const attrs = match[1] || match[3] || ''; const attrs = match[1] || match[3] || '';
@ -205,16 +205,16 @@ function parseTestCases(junit) {
} }
const junit = fs.existsSync(junitPath) ? fs.readFileSync(junitPath, 'utf8') : ''; const junit = fs.existsSync(junitPath) ? fs.readFileSync(junitPath, 'utf8') : '';
const tests = Number((junit.match(/tests="([0-9]+)"/) || [])[1] || 0); const tests = Number((junit.match(new RegExp('tests="([0-9]+)"')) || [])[1] || 0);
const failures = Number((junit.match(/failures="([0-9]+)"/) || [])[1] || 0); const failures = Number((junit.match(new RegExp('failures="([0-9]+)"')) || [])[1] || 0);
const errors = Number((junit.match(/errors="([0-9]+)"/) || [])[1] || (junit ? 0 : 1)); const errors = Number((junit.match(new RegExp('errors="([0-9]+)"')) || [])[1] || (junit ? 0 : 1));
const skipped = Number((junit.match(/skipped="([0-9]+)"/) || [])[1] || 0); const skipped = Number((junit.match(new RegExp('skipped="([0-9]+)"')) || [])[1] || 0);
const cov = fs.existsSync(coveragePath) ? JSON.parse(fs.readFileSync(coveragePath, 'utf8')) : { total: {} }; const cov = fs.existsSync(coveragePath) ? JSON.parse(fs.readFileSync(coveragePath, 'utf8')) : { total: {} };
const total = cov.total || {}; const total = cov.total || {};
const sourceFiles = sourceRoots.flatMap((root) => collectSourceFiles(root)); const sourceFiles = sourceRoots.flatMap((root) => collectSourceFiles(root));
const overLimitFiles = sourceFiles const overLimitFiles = sourceFiles
.map((file) => ({ file, lines: fs.readFileSync(file, 'utf8').split(/\r?\n/).length })) .map((file) => ({ file, lines: fs.readFileSync(file, 'utf8').split(new RegExp('\\r?\\n')).length }))
.filter((item) => item.lines > 500); .filter((item) => item.lines > 500);
const report = { const report = {
@ -349,7 +349,10 @@ const sourceFilesTotal = Number(quality.hygiene?.sourceFilesTotal ?? 0);
const sourceLinesOver500 = Number(quality.hygiene?.sourceLinesOver500 ?? 0); const sourceLinesOver500 = Number(quality.hygiene?.sourceLinesOver500 ?? 0);
function esc(value) { function esc(value) {
return String(value ?? '').replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n'); return String(value ?? '')
.split('\\').join('\\\\')
.split('"').join('\\"')
.split('\n').join('\\n');
} }
function labelString(labels) { function labelString(labels) {