Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/lib/vcon_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
- attachment / dialog ``mimetype`` → ``mediatype``
- extension/critical: ``must_support`` (top-level or in entries) →
``critical``
- dialog / analysis / attachment ``encoding: "text"`` → ``"none"``. Not a
spec value (``base64url``, ``json``, ``none``); legacy producers use it for
a plain-string body, which is exactly what ``none`` means.

The function is conservative: if both the legacy and the spec field are
present, the spec field wins and the legacy field is dropped.
Expand Down Expand Up @@ -53,6 +56,8 @@ def _normalize_entry(entry: Dict[str, Any]) -> None:
_rename(entry, "schema_version", "schema")
_rename(entry, "mimetype", "mediatype")
_rename(entry, "must_support", "critical")
if entry.get("encoding") == "text":
entry["encoding"] = "none"


def _normalize_attachment(att: Dict[str, Any]) -> None:
Expand Down
16 changes: 16 additions & 0 deletions common/tests/test_vcon_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,19 @@ def test_empty_or_missing_fields_safe():
def test_returns_same_dict():
v = {"uuid": "u"}
assert normalize_legacy_fields(v) is v


def test_legacy_text_encoding_to_none():
v = {
"uuid": "u",
"attachments": [
{"type": "searchable_text", "encoding": "text", "body": "2024 Impreza"},
{"type": "tags", "encoding": "json", "body": "[]"},
],
"analysis": [{"type": "summary", "encoding": "text", "body": "s"}],
}
normalize_legacy_fields(v)
assert v["attachments"][0]["encoding"] == "none"
assert v["attachments"][0]["body"] == "2024 Impreza"
assert v["attachments"][1]["encoding"] == "json"
assert v["analysis"][0]["encoding"] == "none"
Loading