fix: reply-all Cc builder crashes on a non-string To or Cc field (#1700)
This commit is contained in:
@@ -20,7 +20,7 @@ export function extractEmail(addr) {
|
|||||||
export function buildReplyAllCc(data, mine) {
|
export function buildReplyAllCc(data, mine) {
|
||||||
const list = Array.isArray(mine) ? mine : [mine];
|
const list = Array.isArray(mine) ? mine : [mine];
|
||||||
const me = new Set(list.map((a) => (a || '').toLowerCase()).filter(Boolean));
|
const me = new Set(list.map((a) => (a || '').toLowerCase()).filter(Boolean));
|
||||||
const split = (s) => (s || '').split(',').map((x) => x.trim()).filter(Boolean);
|
const split = (s) => (typeof s === 'string' ? s : '').split(',').map((x) => x.trim()).filter(Boolean);
|
||||||
return [...split(data && data.to), ...split(data && data.cc)]
|
return [...split(data && data.to), ...split(data && data.cc)]
|
||||||
.filter((addr) => !me.has(extractEmail(addr)))
|
.filter((addr) => !me.has(extractEmail(addr)))
|
||||||
.join(', ');
|
.join(', ');
|
||||||
|
|||||||
40
tests/test_reply_all_cc_nonstring_js.py
Normal file
40
tests/test_reply_all_cc_nonstring_js.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
"""Pin buildReplyAllCc (static/js/emailLibrary/replyRecipients.js) against a
|
||||||
|
non-string To/Cc. Driven through `node --input-type=module`; skips without node.
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
_REPO = Path(__file__).resolve().parent.parent
|
||||||
|
_HELPER = _REPO / "static" / "js" / "emailLibrary" / "replyRecipients.js"
|
||||||
|
_HAS_NODE = shutil.which("node") is not None
|
||||||
|
|
||||||
|
|
||||||
|
def _cc(data, mine):
|
||||||
|
js = f"""
|
||||||
|
import {{ buildReplyAllCc }} from '{_HELPER.as_posix()}';
|
||||||
|
console.log(JSON.stringify(buildReplyAllCc({json.dumps(data)}, {json.dumps(mine)})));
|
||||||
|
"""
|
||||||
|
proc = subprocess.run(
|
||||||
|
["node", "--input-type=module"],
|
||||||
|
input=js, capture_output=True, text=True, cwd=str(_REPO), timeout=30,
|
||||||
|
)
|
||||||
|
assert proc.returncode == 0, proc.stderr
|
||||||
|
return json.loads(proc.stdout.strip())
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not _HAS_NODE, reason="node binary not on PATH")
|
||||||
|
def test_build_reply_all_cc_tolerates_non_string_fields():
|
||||||
|
# data.to / data.cc come from a JSON message blob and are not always
|
||||||
|
# strings; the old (s || "").split crashed on a non-string To.
|
||||||
|
out = _cc({"to": 123, "cc": "a@x.com, b@x.com"}, "me@x.com")
|
||||||
|
assert out == "a@x.com, b@x.com"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not _HAS_NODE, reason="node binary not on PATH")
|
||||||
|
def test_build_reply_all_cc_still_excludes_self():
|
||||||
|
out = _cc({"to": "me@x.com, a@x.com", "cc": ""}, "me@x.com")
|
||||||
|
assert out == "a@x.com"
|
||||||
Reference in New Issue
Block a user