Skip to content

Globally use invariant culture for number parsing and display + Hardened numeric textboxes against bad input - #36

Merged
milankarman merged 3 commits into
milankarman:mainfrom
Avasam:Globally-use-invariant-culture-for-number-parsing-and-display
Nov 19, 2026
Merged

milankarman merged 3 commits into
milankarman:mainfrom
Avasam:Globally-use-invariant-culture-for-number-parsing-and-display

Conversation

@Avasam

@Avasam Avasam commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

On locales with a , decimal separator, double.Parse on the fps and minimum similarity fields broke when typing a . decimal, which ForceDouble allowed: 29.97 threw FormatException on fr-CA/fr-FR, and silently became 2997 on de-DE. Numbers were also displayed with a , (e.g. 29,97).

  • Set global default culture configuration at App startup, so the conversion thread is covered too
  • Restrict ForceDouble to [0-9.], since , is the thousands separator in the invariant culture
  • Enabled AnalysisModeGlobalization to catch more similar issues, with CA1304, CA1305 and CA1311 disabled as it's configured globally, rather than having to pass in at every call site.

Hardened numeric textboxes against bad input:

  • Validate typed and pasted input against the resulting text, so 1.2 + .5 is rejected
  • Map , to . in decimal fields, since the numpad decimal key types , on some keyboard layouts
  • Trim whitespace and newlines from pasted text
  • Restore the last valid value when a field loses focus empty or holding a lone .
  • Replace bare int.Parse/double.Parse with TryParse fallbacks. Clearing txtVideoFrame or closing MainWindow with an empty step size no longer crashes
  • Fix OverflowException crash when typing a number too large for an int, e.g. in the conversion start/end time or start/end frame fields. ClampInteger clamps it to the maximum instead
  • Compute step size frames as fps * step / 1000. A 0 step no longer divides by zero, and steps over 1000 ms no longer yield infinity. Results are unchanged for step sizes that divide 1000
  • Add missing ForceInteger on txtMinFrames
  • Drop ForceDouble on read-only txtFPS

On locales with a `,` decimal separator, `double.Parse` on the fps and minimum similarity fields broke when typing a `.` decimal, which `ForceDouble` allowed: `29.97` threw `FormatException` on `fr-CA`/`fr-FR`, and silently became `2997` on `de-DE`. Numbers were also displayed with a `,` (e.g. `29,97`).

- Set global default culture configuration at `App` startup, so the conversion thread is covered too
- Restrict `ForceDouble` to `[0-9.]`, since `,` is the thousands separator in the invariant culture
- Enabled `AnalysisModeGlobalization` to catch more similar issues, with CA1304, CA1305 and CA1311 disabled as it's configured globally, rather than having to pass in at every call site.
@Avasam

Avasam commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

I'd say either this, or bother with special casing and edge-cases to ensure that numbers such as 29.97 don't break and is manually coerced on locales that use decimal separator.

Given that all speedrun timers and leaderboards (that I know of) use . as the millisecond separator convention, I think going invariant is perfectly acceptable.

It also makes text output the same, for comparing results with another verifier who'd have a different locale.

@Avasam
Avasam force-pushed the Globally-use-invariant-culture-for-number-parsing-and-display branch from 5ed733f to 0ae9536 Compare November 17, 2026 16:41
@Avasam Avasam changed the title Globally use invariant culture for number parsing and display + Fix textbox validation on paste Globally use invariant culture for number parsing and display + Hardened numeric textboxes against bad input Nov 17, 2026
- Validate typed and pasted input against the resulting text, so `1.2` + `.5` is rejected
- Map `,` to `.` in decimal fields, since the numpad decimal key types `,` on some keyboard layouts
- Trim whitespace and newlines from pasted text
- Restore the last valid value when a field loses focus empty or holding a lone `.`
- Replace bare `int.Parse`/`double.Parse` with `TryParse` fallbacks. Clearing `txtVideoFrame` or closing `MainWindow` with an empty step size no longer crashes
- Fix `OverflowException` crash when typing a number too large for an `int`, e.g. in the conversion start/end time or start/end frame fields. `ClampInteger` clamps it to the maximum instead
- Compute step size frames as `fps * step / 1000`. A `0` step no longer divides by zero, and steps over 1000 ms no longer yield infinity. Results are unchanged for step sizes that divide 1000
- Add missing `ForceInteger` on `txtMinFrames`
- Drop `ForceDouble` on read-only `txtFPS`
@Avasam
Avasam force-pushed the Globally-use-invariant-culture-for-number-parsing-and-display branch from 0ae9536 to d41c034 Compare November 17, 2026 16:47
@milankarman
milankarman merged commit 149e453 into milankarman:main Nov 19, 2026
1 check passed
@Avasam
Avasam deleted the Globally-use-invariant-culture-for-number-parsing-and-display branch November 19, 2026 22:42
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