schlib_write: encode parameter records as UTF-8 (fixes crash on Ω/µ and other non-latin-1 chars in template columns like ESR(mΩ))
parent
7ff9751504
commit
2719f5c75b
Binary file not shown.
|
|
@ -113,7 +113,7 @@ def _uid(name):
|
|||
def _param_record(idx, name, value):
|
||||
s=(f"|RECORD=41|IndexInSheet={idx}|OwnerPartId=1|Justification=4|FontID=2|IsHidden=T"
|
||||
f"|Text={value}|Name={name}|UniqueID={_uid(name)}")
|
||||
payload=s.encode('latin-1')+b'\x00'
|
||||
payload=s.encode('utf-8')+b'\x00' # utf-8: handles Ω, µ, °, ± in names/values
|
||||
return struct.pack('<I',len(payload))+payload
|
||||
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ def _leading_text_records(data):
|
|||
|
||||
|
||||
def _rec_name(block):
|
||||
t=block[4:-1].decode('latin-1')
|
||||
t=block[4:-1].decode('utf-8','replace')
|
||||
return t.split('|Name=')[1].split('|')[0] if '|Name=' in t else None
|
||||
|
||||
|
||||
|
|
@ -142,12 +142,12 @@ def _patch_field(block, field, value):
|
|||
"""Replace |field=...| inside a length-prefixed text record, re-framing its 4-byte length.
|
||||
Used to set the component's ComponentDescription in the RECORD=1 header."""
|
||||
import re
|
||||
text = block[4:-1].decode('latin-1')
|
||||
text = block[4:-1].decode('utf-8', 'replace')
|
||||
if f"|{field}=" in text:
|
||||
text = re.sub(rf"\|{re.escape(field)}=[^|]*", f"|{field}={value}", text, count=1)
|
||||
elif text.startswith("|RECORD="):
|
||||
text = text + f"|{field}={value}"
|
||||
payload = text.encode('latin-1') + b'\x00'
|
||||
payload = text.encode('utf-8') + b'\x00'
|
||||
return struct.pack('<I', len(payload)) + payload
|
||||
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ def write_params(schlib, params_json, out, typeid=None, template=None):
|
|||
ok=True
|
||||
for e in ole.listdir(streams=True):
|
||||
if e[-1].lower()=="data":
|
||||
t=ole.openstream(e).read().decode('latin-1','ignore')
|
||||
t=ole.openstream(e).read().decode('utf-8','ignore')
|
||||
for nm in fields:
|
||||
if f"|Name={nm}|" not in t and f"|Name={nm}\x00" not in t and f"Name={nm}" not in t:
|
||||
ok=False
|
||||
|
|
|
|||
Loading…
Reference in New Issue