diff --git a/lib/__tests__/classification-labels.test.ts b/lib/__tests__/classification-labels.test.ts index ffd41572c..25a7ebb6c 100644 --- a/lib/__tests__/classification-labels.test.ts +++ b/lib/__tests__/classification-labels.test.ts @@ -58,7 +58,8 @@ describe('SIO-Label', () => { it('writes Sensitivity and the extra header only when the label sets them', () => { expect(labelHeaderProperties(confidential, 'X-Classification')).toEqual({ - 'header:SIO-Label:asRaw': sioLabelValue(confidential), + // Without the leading space: the server writes "SIO-Label: " itself. + 'header:SIO-Label:asRaw': 'marking="CONFIDENTIAL"; fgcolor=#000000; bgcolor=#d97706', 'header:Sensitivity:asText': 'Company-Confidential', 'header:X-Classification:asText': 'Confidential', }); diff --git a/lib/classification/labels.ts b/lib/classification/labels.ts index 85a34d03a..86d13007a 100644 --- a/lib/classification/labels.ts +++ b/lib/classification/labels.ts @@ -64,7 +64,7 @@ function percentEncode(value: string): string { /** The marking parameter(s): quoted when ASCII, RFC 2231 (with continuations when long) otherwise. */ function markingParameters(marking: string): string[] { const clean = marking.replace(/["\\\r\n]/g, ''); - // eslint-disable-next-line no-control-regex + if (/^[\x20-\x7e]*$/.test(clean)) return [`marking="${clean}"`]; const encoded = percentEncode(clean); const MAX = 60; @@ -116,13 +116,14 @@ function labelHeaderPairs(label: ClassificationLabel, extraHeader: string): Arra export function labelHeaderProperties(label: ClassificationLabel, extraHeader: string): Record { const out: Record = {}; for (const [name, value, form] of labelHeaderPairs(label, extraHeader)) { - out[form === 'raw' ? `header:${name}:asRaw` : `header:${name}:asText`] = value; + // The server writes "Name: " itself; a raw value keeps only its own folds. + out[form === 'raw' ? `header:${name}:asRaw` : `header:${name}:asText`] = form === 'raw' ? value.trimStart() : value; } return out; } function encodedWord(value: string): string { - // eslint-disable-next-line no-control-regex + if (/^[\x20-\x7e]*$/.test(value)) return value; let binary = ''; for (const byte of new TextEncoder().encode(value)) binary += String.fromCharCode(byte);