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
+14 -7
View File
@@ -6962,13 +6962,20 @@ async def drawing_properties_set(
engine (`capability: dwgprops` — SummaryInfo lives in the DWG, a DXF has
no slot for it; custom properties still work headlessly), a non-string
value (`TypeError` naming the field or key — nothing is coerced with
`str()`), an empty custom key, a custom key AutoCAD's AddCustomInfo would
reject mid-write (leading/trailing whitespace, `=`, `;`, no-break space —
`ValueError` naming the key, on both engines), a line break in a custom
key or value (it corrupts the DXF on save), and headlessly a document
older than R2004 (`ValueError` — ezdxf only writes the custom-property
header pairs for AC1018+, so they would vanish at save; save as R2004 or
newer first). On the live engine a custom key is added with AddCustomInfo
`str()`), an empty custom key, a custom key to *write* that AutoCAD's
AddCustomInfo would reject mid-write (measured on AutoCAD 2026: leading or
trailing whitespace, or any of the thirteen characters
`" * , / : ; < = > ? \\ ` |` anywhere in the key; internal spaces, tabs
and unicode are fine — `ValueError` naming the key, on both engines; a
delete is exempt because RemoveCustomByKey never validates syntax, so a
key that reached the drawing another way stays removable), two keys in
one request that differ only by case (custom keys are case-insensitive in
AutoCAD), a line break in a custom key or value (it corrupts the DXF on
save), and headlessly a document older than R2004 (`ValueError` — ezdxf
only writes the custom-property header pairs for AC1018+, so they would
vanish at save; save as R2004 or newer first). A key is matched to the
drawing case-insensitively on both engines and keeps its stored spelling
when updated. On the live engine a custom key is added with AddCustomInfo
when new and changed with SetCustomByKey when present.
"""
summary = {