Skip to content

feat(vba): encoding robustness — UTF-8 BOM strip and Windows-1252 fallback for VBA files #53

Description

@ardelperal

Priority

P3 — defense in depth; dysflow normally guarantees UTF-8.

Context

Access SaveAsText / VBIDE Export write Windows-1252 (ANSI). dysflow converts everything to UTF-8-no-BOM on export (Convert-AnsiToUtf8NoBom in scripts/dysflow-vba-manager.ps1) and offers a Fix-Encoding action. But codegraph-vba can be pointed at exports produced by other tools, older dysflow runs, or hand-copied modules that are still CP1252 on disk.

Current behavior

Files are read as UTF-8 unconditionally. A CP1252 file with accented identifiers — ubiquitous in Spanish-language Access code (Sub ActualizarSituación, enum member , module headers ' MÓDULO:) — decodes to replacement characters, \p{L} regexes stop matching, and the symbol silently disappears from the graph. A BOM-carrying UTF-8 file additionally corrupts the first line (breaks Attribute VB_Name detection → wrong module name).

Expected behavior

  • UTF-8 BOM stripped before extraction.
  • When a .bas/.cls/.form.txt/.report.txt file's bytes are invalid UTF-8, fall back to decoding as Windows-1252 (cheap sniff: TextDecoder('utf-8', { fatal: true }) throws → re-decode as windows-1252, which Node's TextDecoder supports).
  • Optionally surface a low-severity ExtractionError/warning noting the fallback so users learn to normalize.

Implementation sketch

  • Locate the single point where VBA-routed file content is read (extraction orchestration / file-read helper) and wrap the decode for VBA-family extensions only — do NOT change decoding for tree-sitter languages.
  • BOM strip: if (text.charCodeAt(0) === 0xFEFF) text = text.slice(1).
  • Unit tests with fixture buffers: CP1252 bytes for Sub Función(), UTF-8-BOM file, plain UTF-8 (unchanged path).

Acceptance criteria

  • CP1252 file yields the same nodes as its UTF-8 twin.
  • UTF-8-BOM file resolves Attribute VB_Name correctly.
  • Valid UTF-8 path byte-identical to today (no behavior change, no perf cliff — sniff only on decode failure).

Validation

Re-index C:\Proyectos\dysflow\E2E_testing\src (all UTF-8): zero delta. Corrupt one copy to CP1252 in a temp fixture and verify parity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vbaVBA/Access-specific work (parent codegraph product)enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions