Skip to content

Fix incorrect unit display names: preserve hyphens and fix whitespace normalization#15

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-bugs-in-generated-units
Draft

Fix incorrect unit display names: preserve hyphens and fix whitespace normalization#15
Copilot wants to merge 2 commits intomainfrom
copilot/fix-bugs-in-generated-units

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 24, 2026

Two bugs in the unit name processing pipeline were producing incorrect display names in the generated C# units (e.g., "kilogramforce" instead of "kilogram-force", "volt ampere" instead of "volt - ampere").

Bug 1 — normalize_unit_name incorrectly stripped hyphens (normalizer.py)

The method removed all - characters from unit names, citing pint parsing issues. Unit names are never passed to pint (only symbol and conversion_factor are), so the stripping only corrupted display values.

# Before — hyphens stripped for no valid reason
return normalized_name.replace("-", "")

# After — just normalize whitespace like every other string field
return Normalizer.normalize_value(name)

Affected names include kilogram-force, pound-force, milli-inch, volt - ampere, and ~30 others. Names like "volt - ampere" additionally produced double spaces ("volt ampere") since the surrounding spaces were left behind after - removal.

Bug 2 — Sanitize discarded whitespace normalization result (Generator.cs)

The regex replace result was never assigned back, leaving multi-whitespace sequences intact in generated C# string literals.

// Before — result discarded
WhitespaceRegex().Replace(value, " ");

// After
value = WhitespaceRegex().Replace(value, " ");

Impact

  • parsedUneceUnits.json regenerated with correct names
  • C# generated files regenerated — property names now properly cased (e.g., KilogramForce instead of Kilogramforce) and Name values match the UNECE standard

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…tion in Sanitize

Co-authored-by: jakubsemerak <3141116+jakubsemerak@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze and fix bugs in generated units Fix incorrect unit display names: preserve hyphens and fix whitespace normalization Feb 24, 2026
Copilot AI requested a review from jakubsemerak February 24, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants