Skip to content

MDL writer: underbar_to_space emits special chars unquoted #330

Closed

Description

@bpowers

Description

The underbar_to_space() function in src/simlin-engine/src/mdl/writer.rs emits variable names bare after converting underbars to spaces, without checking whether the resulting identifier contains MDL-special characters ($, /, |, etc.). This produces unparseable MDL output for models with non-standard identifier names.

For example, a variable named $_euro (stored internally as $_euro) would be emitted as:

$ euro=
    ...

instead of the correct quoted form:

"$ euro"=
    ...

The Vensim MDL format requires identifiers containing special characters to be enclosed in double-quotes.

Why it matters

This is a correctness gap -- the MDL writer silently produces invalid output for certain inputs rather than failing or handling them properly. While no current test model exercises this path (all 42 roundtrip files use standard alphanumeric names), real-world Vensim models can and do use special characters in variable names.

Components affected

  • src/simlin-engine/src/mdl/writer.rs -- underbar_to_space() and all call sites that emit variable names

Possible approaches

  1. Add a needs_quoting() check (similar to the existing one in src/simlin-engine/src/ast/mod.rs:293) that detects identifiers requiring quoting.
  2. Wrap identifiers that need quoting in double-quotes when emitting them.
  3. Add a test model (or at minimum a unit test) with special-character identifiers to exercise this path.

Context

Identified during review of PR #324 (MDL writer). No existing roundtrip test model uses special characters in identifiers, so this path is currently untested.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions