From 116ade4630c87a424c53eda1765a48ee334d20ee Mon Sep 17 00:00:00 2001 From: red person Date: Wed, 3 Jun 2026 08:16:48 +0300 Subject: [PATCH] Ignore non-string signature fold metadata (#1655) --- static/js/emailLibrary/signatureFold.js | 2 +- tests/test_signature_fold_js.py | 63 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/test_signature_fold_js.py diff --git a/static/js/emailLibrary/signatureFold.js b/static/js/emailLibrary/signatureFold.js index 0dda486..474778c 100644 --- a/static/js/emailLibrary/signatureFold.js +++ b/static/js/emailLibrary/signatureFold.js @@ -133,7 +133,7 @@ export function _foldSummary(label, iconSvg, meta) { // "On , 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(//gi, '') .replace(/<[^>]+>/g, ' ') diff --git a/tests/test_signature_fold_js.py b/tests/test_signature_fold_js.py new file mode 100644 index 0000000..3ccaffc --- /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 Sent: Monday, May 4, 2026 To: Bob Subject: hi'; + console.log(JSON.stringify({ meta: _extractQuoteMeta(html) })); + """ + ) + + assert values["meta"] == "Alice · Monday, May 4, 2026"