git fixec null symbol

This commit is contained in:
2026-09-02 13:45:27 +03:00
parent dfc71c0130
commit 8bf360d583
2 changed files with 48 additions and 20 deletions
+17 -1
View File
@@ -8,11 +8,22 @@ from pathlib import Path
from typing import Optional
def sanitize_text(value: str | None) -> str:
"""Remove NUL bytes — PostgreSQL text fields reject them; SchDoc may contain them."""
if not value:
return ""
return value.replace("\x00", "")
@dataclass
class ComponentProperty:
name: str
text: str
def __post_init__(self) -> None:
self.name = sanitize_text(self.name)
self.text = sanitize_text(self.text)
@dataclass
class DielProperty:
@@ -22,6 +33,10 @@ class DielProperty:
diel_type: int
layer_number: int
def __post_init__(self) -> None:
self.name = sanitize_text(self.name)
self.value = sanitize_text(self.value)
@dataclass
class ProjectData:
@@ -342,6 +357,7 @@ class AltiumParser:
def make_complex_string(text: str, props: list[ComponentProperty]) -> str:
text = sanitize_text(text)
if not text.startswith("="):
return text
expr = text[1:]
@@ -351,7 +367,7 @@ def make_complex_string(text: str, props: list[ComponentProperty]) -> str:
key = m.group(1)
return mapping.get(key, "")
return re.sub(r"['\"]([^'\"]+)['\"]", repl, expr)
return sanitize_text(re.sub(r"['\"]([^'\"]+)['\"]", repl, expr))
def find_prjpcb(extract_dir: Path) -> Optional[Path]: