Repository navigation
fix(core): make numeric formatting and parsing culture-invariant - #663
Merged
Merged
Conversation
The server expects numbers in a fixed, culture-independent format, but the client formatted arguments and parsed replies using the current culture. Under cultures such as sv-SE (U+2212 minus sign) or tr-TR (dotted capital I), the client could send arguments that the server rejects. - Format arguments and parse replies with the invariant culture. - Enable Meziantou MA0011/MA0075/MA0076 as errors to prevent regressions; track the remaining Meziantou rules in valkey-io#662. - Run tests under the invariant culture via xunit.runner.json. - Keep GeoPosition and SortedSetEntry ToString() culture-sensitive for StackExchange.Redis compatibility. - Add a ToString(RequestType, args) helper for string replies. Closes valkey-io#651 Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
Signed-off-by: currantw <taylor.curran@improving.com>
nderraugh
approved these changes
Nov 19, 2026
leslie-bq
approved these changes
Nov 20, 2026
leslie-bq
left a comment
Collaborator
There was a problem hiding this comment.
Minor nit, non-blocking, LGTM.
Signed-off-by: currantw <taylor.curran@improving.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make the C# client culture-invariant. The server expects numbers in a fixed, culture-independent format (e.g.
-1,13.361389), but the client formatted arguments and parsed replies usingCultureInfo.CurrentCulture. As a result, applications running under some non-English cultures could send arguments that the server rejects. After this change, the client formats every argument and parses every reply with the invariant culture, and analyzers prevent regressions.Issue Link
Closes #651.
Features and Behaviour Changes
Culture-invariant arguments: numbers are always sent in invariant form:
sv-SE,fa-IR, and similar cultures, negative integers were sent with a Unicode minus sign (U+2212) and rejected by the server (e.g.INCRBY key -5).tr-TR,BITFIELD ... OVERFLOW FAILwas sent asOVERFLOW FAİLand rejected by the server. The subcommand argument was built withOverflowType.Fail.ToString().ToUpper(), and in Turkish, uppercaseiis the dotted capitalİ(U+0130), not ASCIII. It now usesToUpperInvariant().WRAPandSATcontain noi, so they were not affected.Culture-invariant reply parsing: replies are parsed with the invariant culture.
Unchanged display output:
GeoPosition.ToString()andSortedSetEntry.ToString()still use the current culture, matching StackExchange.Redis.Regression prevention:
task lintnow fails on culture-sensitive formatting, parsing, and casing:IFormatProvideris missing.ToString.ToStringin interpolated strings.These rules come from Meziantou.Analyzer, which is added as a new development-only analyzer dependency.
Implementation
CultureInfo.InvariantCultureat every place that formats or parses a number.GlideString, use the invariantToGlideString()extension instead.ToLong/ToDouble/TryToLong/TryToDoublehelpers rather thanx.ToString()..editorconfig, all C# files):TryParsewithout a format provider and culture-sensitive casing (ToUpper/ToLower). CA1305 missed both theMEMORY STATSTryParseand theBITFIELDToUpperbugs. MA0075 and MA0076 also catch culture-sensitive string concatenation and interpolation, which CA1305 doesn't check.MeziantouAnalysisMode=None, so only rules opted into in.editorconfigrun. This mirrors the Roslynator and StyleCop setup. The remaining rules are listed under aTODOfor task(lint): enable Meziantou analyzers #662.xunit.runner.jsonsets"culture": "invariant", so results don't depend on the developer's machine culture.Request.ToString(RequestType, args)helper for commands with string replies.LolwutOptions.ToArgs()now returnsGlideString[].#pragma warning disablefromConfigurationOptions.csand fixed the violations:ifstatements,_trustedIssuers,_clientCertificate, and_clientKey.Limitations
None
Testing
GlideStringTests.ToGlideString_NonAsciiNegativeSign_UsesInvariantCulture, which runs undersv-SE.Related Issues
Checklist
No documentation changes needed;CHANGELOG.md,README.md,DEVELOPER.md, and other documentation files are updated.CHANGELOG.mdis updated at release time.mainor releasemain, squash otherwise.