Skip to content

Some special characters (math operators and other punctuation) not handled when converting variable names to canonical IDs #794

@chrispcampbell

Description

@chrispcampbell

I received access to the model referenced in discussion #790. There are a few issues affecting that model that need to be fixed in SDEverywhere. The following describes one of those defects.

Current Behavior

The canonicalId() function in packages/parse/src/_shared/canonical-id.js converts Vensim variable names into C/JS identifiers. It handles a specific set of special characters ('".,\-$&%/|()) but does NOT handle other characters that Vensim allows in variable names, such as:

  • Operators: +, >, <, =
  • Other symbols: #, @, ^, *, ~, ?, :, ;

Any of those (and other) symbols should be valid as long as they are inside double quotes, per the Vensim docs (see Rules for Variable Names).

When a Vensim model contains a variable name like "A+B" or "GDP>0", the generated identifier contains invalid characters (_a+b, _gdp>0) which cause JavaScript/C syntax errors.

Real-world models contain variable names with +, >, <, and accented characters. Users currently have to apply post-processing workarounds to fix the generated code.

Expected Behavior

We should change the regex so that other special characters are converted to underscore like we do for the current limited set of special characters.

Notes

  • There is a known limitation of our current approach for converting to canonical IDs. We should consider a different strategy for converting names to IDs to avoid this, but it's not likely to come up in practice so I will leave that for another day (it will not be addressed as part of this issue).

/cc @LSarribouette @m2gi-mohamami

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions