Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (self): escape markdown table cells, fix stale canonical-source comment

[._.]/ Adam Eivy72cf9f7ec67c
diff --git a/client/src/lib/clinicianReport.js b/client/src/lib/clinicianReport.js
index f98efc485f..1919b77997 100644
--- a/client/src/lib/clinicianReport.js
+++ b/client/src/lib/clinicianReport.js
@@ -9,8 +9,9 @@
import { REFERENCE_RANGES, getBloodValueStatus } from '../components/meatspace/constants.js';
-// Blood-marker category grouping — mirrors BloodTestCard's getCategoryForKey so
-// the printed report sections match the on-screen tab grouping.
+// Blood-marker category grouping — canonical source for the marker→category map.
+// BloodTestCard imports getCategoryForKey from here so the on-screen tab grouping
+// and the printed report stay in sync.
const CATEGORY_KEYS = {
'Metabolic Panel': [
'glucose', 'bun', 'creatinine', 'egfr', 'na', 'k', 'ci', 'co2',
@@ -152,6 +153,12 @@ export function buildClinicianReport({ tests = [], config = null, generatedAt =
};
}
+// Escape values for a markdown table cell so free-text fields (e.g. a chronic
+// condition containing `|` or a newline) can't break the table layout.
+function mdCell(value) {
+ return String(value ?? '').replace(/\|/g, '\\|').replace(/\r?\n/g, ' ');
+}
+
/** Serialize a report model to clipboard-friendly markdown. */
export function reportToMarkdown(report) {
if (!report) return '';
@@ -168,7 +175,7 @@ export function reportToMarkdown(report) {
lines.push('| Factor | Value | Note |');
lines.push('| --- | --- | --- |');
for (const row of report.lifestyle) {
- lines.push(`| ${row.label} | ${row.value} | ${row.note || ''} |`);
+ lines.push(`| ${mdCell(row.label)} | ${mdCell(row.value)} | ${mdCell(row.note || '')} |`);
}
lines.push('');
@@ -195,7 +202,7 @@ export function reportToMarkdown(report) {
lines.push('| --- | --- | --- | --- |');
for (const m of markers) {
const value = `${m.value}${m.unit ? ` ${m.unit}` : ''}`;
- lines.push(`| ${m.label} | ${value} | ${formatRange(m.range)} | ${STATUS_LABELS[m.status]} |`);
+ lines.push(`| ${mdCell(m.label)} | ${mdCell(value)} | ${formatRange(m.range)} | ${STATUS_LABELS[m.status]} |`);
}
lines.push('');
}
diff --git a/client/src/lib/clinicianReport.test.js b/client/src/lib/clinicianReport.test.js
index 5a545b8bd6..728e459f20 100644
--- a/client/src/lib/clinicianReport.test.js
+++ b/client/src/lib/clinicianReport.test.js
@@ -137,4 +137,16 @@ describe('buildClinicianReport + reportToMarkdown', () => {
it('returns empty string for a null report', () => {
expect(reportToMarkdown(null)).toBe('');
});
+
+ it('escapes pipes and newlines in free-text cells so the table stays intact', () => {
+ const md = reportToMarkdown(buildClinicianReport({
+ tests: [],
+ config: { lifestyle: { chronicConditions: ['asthma | mild', 'line1\nline2'] } },
+ }));
+ const conditionRow = md.split('\n').find(l => l.startsWith('| Chronic conditions'));
+ expect(conditionRow).toContain('asthma \\| mild');
+ expect(conditionRow).not.toMatch(/\n/);
+ // The escaped row still has exactly the 3-column table shape (leading + trailing pipe + 2 separators).
+ expect(conditionRow.match(/(?<!\\)\|/g)).toHaveLength(4);
+ });
});