From 1f9dfdd93434c2e41eb81020ff2c837fdc09a540 Mon Sep 17 00:00:00 2001 From: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> Date: Mon, 22 Sep 2025 15:30:00 +0200 Subject: [PATCH] harden: use regex for robust markdown table parsing - Replace brittle column index parsing with regex matching - Escape special characters in metric names for safe regex - More reliable parsing against column drift and table format variations - Prevents false matches from substring matching --- .github/scripts/parse-metrics.mjs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/scripts/parse-metrics.mjs b/.github/scripts/parse-metrics.mjs index a9c351f4..e238c8aa 100644 --- a/.github/scripts/parse-metrics.mjs +++ b/.github/scripts/parse-metrics.mjs @@ -7,19 +7,12 @@ function parseMetricsTable(content, metricName) { for (let i = 0; i < lines.length; i++) { const line = lines[i].trim(); - if (line.includes(metricName)) { - // Split by | and get the value column, filtering empty strings - const columns = line - .split('|') - .map((col) => col.trim()) - .filter((col) => col.length > 0); - // Look for the value in columns 1-3 (accounting for different table formats) - for (let j = 1; j < Math.min(columns.length, 4); j++) { - const value = columns[j]; - if (value && value !== '---' && value !== metricName) { - return value; - } - } + // Match a markdown table row like: | Metric Name | value | ... + const safeName = metricName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const re = new RegExp(`^\\|\\s*${safeName}\\s*\\|\\s*([^|]+)\\|?`); + const match = line.match(re); + if (match) { + return match[1].trim() || 'N/A'; } } return 'N/A';