Repository navigation
fix: parse integers with the reader culture instead of the current culture - #49
Merged
VisualBean merged 1 commit intoOct 17, 2026
Conversation
…lture ValueNode.GetIntegerValue/GetLongValue (and their OrDefault variants) called int/long.TryParse without a culture, so they used CultureInfo.CurrentCulture, while GetScalarValue formats the value with Settings.CultureInfo (invariant by default). On machines whose current culture has a non-ASCII negative sign (ar-*, he-IL, fa-IR, ... - 57 of 890 .NET cultures), every negative integer failed to parse: e.g. ROS2 `deadline: -1` was silently dropped and IBM MQ `expiry: -5` produced "Value could not parse to long." Both now parse with Settings.CultureInfo, matching how the JSON Schema and Avro deserializers already parse numbers. Also switch Avro decimal `precision`/`scale` from int.Parse to GetIntegerValue: int.Parse threw FormatException for a non-integer value, which escaped the reader instead of becoming a diagnostic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
bielu
marked this pull request as ready for review
October 17, 2026 17:44
VisualBean
approved these changes
Oct 17, 2026
VisualBean
left a comment
Contributor
There was a problem hiding this comment.
All of the binding infra is from before I added culture to the options.
Very good change
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.
Problem
ValueNode.GetIntegerValue,GetLongValueand theirOrDefaultvariants callint.TryParse(s, out ...)/long.TryParse(s, out ...)with no culture, so they parse withCultureInfo.CurrentCulture.GetScalarValueformats the value withSettings.CultureInfo, which is invariant by default. The two don't match.On a machine whose current culture uses a non-ASCII negative sign, every negative integer fails to parse. That covers 57 of the 890 cultures in .NET 10, including all
ar-*,he-IL,fa-IRandckb. Arabic, for example, usesU+061C U+002D. The result:deadline: -1, the spec's value for "infinite", is silently read asnull, because it goes throughGetIntegerValueOrDefault.expiry: -5givesValue could not parse to long.The same document reads fine on an
en-USmachine, which makes this hard to diagnose.Separately, Avro decimal
precisionandscaleusedint.Parse(...). A non-integer value threwFormatException, which escapedReadFragment/Readinstead of becoming a diagnostic.Change
ValueNodeinteger and long parsing now usesNumberStyles.IntegerwithSettings.CultureInfo, the same cultureGetScalarValueformats with. The JSON Schema and Avro deserializers already parse numbers this way (double.Parse(..., n.Context.Settings.CultureInfo)).precisionandscaleusen.GetIntegerValue(), so invalid values are reported indiagnostic.Errors.Tests
Added
IntegerParsing_Should(7 cases):intvalues underar-SA,he-ILandfa-IR(ROS2 QoS durations) and negativelongvalues underar-SAandhe-IL(IBM MQexpiry).precisionandscaleset to"abc"report an error instead of throwing.The test class is
[NonParallelizable]and restoresCurrentCultureinTearDown. All 7 fail onvnextand pass with this change; the full suite passes on net8.0/net9.0/net10.0.🤖 Generated with Claude Code