Skip to content

Self-hosted AI workspace.

Python

Ignore non-string signature fold metadata (#1655)

red person906da91f4a10
diff --git a/static/js/emailLibrary/signatureFold.js b/static/js/emailLibrary/signatureFold.js
index 0dda486f1..474778c03 100644
--- a/static/js/emailLibrary/signatureFold.js
+++ b/static/js/emailLibrary/signatureFold.js
@@ -133,7 +133,7 @@ export function _foldSummary(label, iconSvg, meta) {
// "On <date>, <addr> wrote:". Returns a display string like
// "Jane Doe · Mon, Apr 18, 2026 at 9:31 AM" or `''`.
export function _extractQuoteMeta(html) {
- if (!html) return '';
+ if (typeof html !== 'string' || !html) return '';
const txt = html
.replace(/<style[\s\S]*?<\/style>/gi, '')
.replace(/<[^>]+>/g, ' ')
diff --git a/tests/test_signature_fold_js.py b/tests/test_signature_fold_js.py
new file mode 100644
index 000000000..3ccaffc5a
--- /dev/null
+++ b/tests/test_signature_fold_js.py
@@ -0,0 +1,63 @@
+import json
+import shutil
+import subprocess
+from pathlib import Path
+
+import pytest
+
+
+ROOT = Path(__file__).resolve().parents[1]
+pytestmark = pytest.mark.skipif(not shutil.which("node"), reason="node binary not on PATH")
+
+
+def _node_eval(source: str):
+ result = subprocess.run(
+ ["node", "--input-type=module", "-e", source],
+ cwd=ROOT,
+ check=True,
+ capture_output=True,
+ text=True,
+ )
+ return json.loads(result.stdout)
+
+
+def test_extract_quote_meta_ignores_non_string_inputs():
+ values = _node_eval(
+ """
+ globalThis.document = {
+ createElement() {
+ return {
+ set textContent(value) { this._text = value; },
+ get innerHTML() { return this._text || ''; }
+ };
+ }
+ };
+ const { _extractQuoteMeta } = await import('./static/js/emailLibrary/signatureFold.js');
+ console.log(JSON.stringify({
+ nullValue: _extractQuoteMeta(null),
+ objectValue: _extractQuoteMeta({bad: true})
+ }));
+ """
+ )
+
+ assert values == {"nullValue": "", "objectValue": ""}
+
+
+def test_extract_quote_meta_keeps_outlook_headers():
+ values = _node_eval(
+ """
+ globalThis.document = {
+ createElement() {
+ return {
+ set textContent(value) { this._text = value; },
+ get innerHTML() { return this._text || ''; }
+ };
+ }
+ };
+ const { _extractQuoteMeta } = await import('./static/js/emailLibrary/signatureFold.js');
+ const html = 'From: Alice <[email protected]> Sent: Monday, May 4, 2026 To: Bob Subject: hi';
+ console.log(JSON.stringify({ meta: _extractQuoteMeta(html) }));
+ """
+ )
+
+ assert values["meta"] == "Alice · Monday, May 4, 2026"