Skip to content

Fraction/int/bool literals are silently corrupted or dropped when deserialized under a non-invariant current culture #73

Description

@matt-edmondson

What's wrong

Coder/Serialization/YamlDeserializer.cs uses double.TryParse/int.TryParse/bool.TryParse at 14+ call sites (e.g. line 1263, and around lines 121-122, 1261-1262) with no CultureInfo/NumberStyles argument, so they parse against Thread.CurrentThread.CurrentCulture. YamlSerializer.SerializeLiteralExpression (YamlSerializer.cs:842) writes numeric literals through YamlDotNet's scalar emitter, which uses an invariant, dot-decimal representation (e.g. 3.14).

double.TryParse(string)'s default NumberStyles is Float | AllowThousands. On a culture where . is the group separator and , is the decimal separator (most of continental Europe: de-DE, fr-FR, es-ES, it-IT, ru-RU, pl-PL, nl-NL, etc.), "3.14" parses as 314 — a silent, wrong value, not an error. On cultures where parsing fails outright, the literal is silently dropped from the loaded AST.

Every generator and the inspector already parse/format with CultureInfo.InvariantCulture explicitly (Coder/Languages/LanguageGeneratorBase.cs:125,133, CSharpGenerator.cs:100,106, Coder.Graph/AstFields.cs:651), so this reads as an isolated oversight in YamlDeserializer.cs.

Failure scenario

Run Coder.Editor (or any consumer of YamlDeserializer) on a machine whose OS/thread culture is e.g. de-DE, open a .coder.yaml document containing a fraction literal such as 3.14; it loads back as 314.0 (or another wrong value) with no error reported, and round-tripping the file silently changes program behavior.

Suggested fix

Pass NumberStyles.Float, CultureInfo.InvariantCulture (and CultureInfo.InvariantCulture for the int/bool parses) at every TryParse in YamlDeserializer.cs, matching the pattern already used in AstFields.cs.

Acceptance criteria

A test that sets CultureInfo.CurrentCulture to de-DE around a serialize→deserialize round trip of a fraction literal asserts the value round-trips correctly.

Activity

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

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions