fix(task-16): custom keys mirror AutoCAD's full AddCustomInfo rule, deletes are exempt, keys match case-insensitively

The 2b9791f fix mirrored only the characters the first review happened to
measure ('=' and ';'), so `custom={'AAA': 'first', 'A:B': 'x', 'ZZZ': 'never'}`
still raised from AddCustomInfo('A:B') on the live engine after subject and
AAA were applied -- the same half-write for 11 other keys. Re-measured on
AutoCAD 2026 by sweeping every character 0x20-0x7E through a scratch
document: exactly thirteen printable characters are 'Invalid key' anywhere
in a key (" * , / : ; < = > ? \ ` |); control characters, internal spaces,
a no-break space and unicode are accepted; leading/trailing whitespace
(space, tab, NBSP) is refused. `_CUSTOM_KEY_FORBIDDEN` is now that set,
the internal-NBSP refusal (wrong: measured accepted) is gone, and the
validator / tool docstrings state the measured rule instead of a closed
enumeration that was false.

A delete (`{key: None}`) is exempt from the AddCustomInfo syntax rules:
RemoveCustomByKey never validates syntax (measured: 'Key not found', never
'Invalid key'), and 2b9791f ran the check before the None branch, so a key
an ezdxf script wrote ('A=B', ' PAD ') showed in drawing_properties_get and
could never be removed. The line-break rule still applies both ways.

Also measured: custom keys are case-insensitive in AutoCAD (AddCustomInfo
over an existing case-variant is 'Duplicate key'; SetCustomByKey and
RemoveCustomByKey match either spelling and keep the stored one). The COM
routing was case-sensitive, so `{'PROJECT': ...}` over 'Project' went to
AddCustomInfo and failed mid-write -- the same class. Both engines now
match existing keys casefolded (update in place under the stored spelling,
never a second tag), and a request naming two case-variants is refused.

Tests: parametrized validator sweep over all thirteen characters, the
accepted set (control chars, NBSP, unicode, the other printables), the
delete exemption headlessly on a DXF carrying such keys and on the fake
SummaryInfo, case-variant refusal, and case-insensitive routing against a
fake that raises 'Duplicate key' / 'Key not found' like AutoCAD. Confirmed
live through the real ComBackend on a scratch document (Close(False)).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FKFStjEFzpGyLq5bMpWxTd
This commit is contained in:
Umut CAN
2026-09-21 21:37:44 +03:00
co-authored by Claude Opus 5
parent 2b9791fbcd
commit 4fe2d963c0
5 changed files with 277 additions and 46 deletions
+10 -3
View File
@@ -4293,22 +4293,29 @@ class ComBackend(AutoCADBackend):
def _sync():
info = _acad_doc().SummaryInfo
# AutoCAD's custom keys are case-insensitive (measured on 2026:
# AddCustomInfo("PROJECT") over an existing "Project" raises
# 'Duplicate key'; SetCustomByKey / RemoveCustomByKey match either
# spelling and the stored spelling is kept), so existence is
# checked casefolded — a case-sensitive check routed "PROJECT" to
# AddCustomInfo and failed mid-write after the summary fields and
# the earlier keys were already applied.
existing: set[str] = set()
for index in range(int(info.NumCustomInfo())):
key, _value = info.GetCustomByIndex(index)
existing.add(str(key))
existing.add(str(key).casefold())
for field, value in written.items():
setattr(info, _SUMMARY_ATTRS[field], value)
for key, value in to_write.items():
# AddCustomInfo on an existing key raises in AutoCAD; SetCustomByKey
# on a missing one does too — route by what is really there.
if key in existing:
if key.casefold() in existing:
info.SetCustomByKey(key, value)
else:
info.AddCustomInfo(key, value)
deleted = []
for key in to_delete:
if key in existing:
if key.casefold() in existing:
info.RemoveCustomByKey(key)
deleted.append(key)
return {