DevToys-app / DevToys

A Swiss Army knife for developers.
https://devtoys.app/
MIT License
26.59k stars 1.42k forks source link

Yaml to Json Conversion is using comma instead of period symbol on float values #1023

Closed LuscasLeo closed 2 months ago

LuscasLeo commented 7 months ago

Current behavior

When converting a yaml content with float props values, the json output value uses the wrong decimal separator image

How to reproduce it (as minimally and precisely as possible)

Accessing DevToys, going on Converters and then JSON <> Yaml option, insert a value line floatvalue: 1.0

Expected behavior

Expected that the json output to follow the RFC 8259

Screenshots

image

Workaround

No response

Affected platforms

Windows

Affected DevToys kind

DevToys (app with GUI)

DevToys Version

Versão 1.0.13.0 | X64 | RELEASE | 2706c6c2 | 2706c6c2 | OS Build 22631.3007

Relevant Assets/Logs

No response

dschonholtz commented 6 months ago

Yaml to Json Conversion is using comma instead of period symbol on float values

Current behavior

When converting a yaml content with float props values, the json output value uses the wrong decimal separator

How to reproduce it (as minimally and precisely as possible)

Accessing DevToys, going on Converters and then JSON <> Yaml option, insert a value line floatvalue: 1.0

Expected behavior

Expected that the json output to follow the RFC 8259

Workaround

No response

Affected platforms

Windows

Affected DevToys kind

DevToys (app with GUI)

Relevant Code and Potential Causes

The issue with the decimal separator in float values during YAML to JSON conversion may be related to the handling of float parsing in the JsonYamlToolViewModel.cs file. The FloatParseHandling property of the JsonSerializerSettings is set to Decimal, which may not account for locale-specific decimal separators:

private readonly JsonSerializerSettings _defaultJsonSerializerSettings = new()
{
    FloatParseHandling = FloatParseHandling.Decimal
};

This setting is used in both JsonHelper.cs and YamlHelper.cs when converting between JSON and YAML. If the system's locale expects a comma as the decimal separator, this could lead to the observed behavior where the conversion process uses a comma instead of a period.

To address this issue, the conversion logic in JsonHelper.cs and YamlHelper.cs may need to be updated to ensure that the correct decimal separator is used based on the system's locale settings or to enforce the use of a period as per the RFC 8259 standard regardless of locale.

Disclaimer

Hey there,

I'm Doug, I'm a SWE working on a ticket specification bot to help get folks understanding specific bugs faster We are trying to test out our product on various open source repos like this one.

Here is what our bot churned out for this ticket. If you found it helpful or have feedback just reply to this comment, I'll be watching it. Otherwise, I just hope this is helpful. Our thing isn't ready to sell yet, but you can find more info on our website: www.AI-Maintainer.com

In the meantime, I haven't been paid to write C# in a looooonnngg time and the bot still gets stuff wrong, but looking at the code this seems at least like a decent starting point. If you could give feedback good and bad I'd love you for it. I genuinely hope this is just useful though.

As a side note, it seems like the default in Brazil, where you are from @LuscasLeo , uses a comma in the scenario you described. So this might be hard for the devs to reproduce until they switch their locale to Brazil or similar. Hence this bug not being caught previously. So you may need to adjust your locale settings locally, or the devs need to enforce consistent usage between conversions.

HansBambel commented 2 months ago

This issue is also present in Version 2.0-preview.1.

I just updated for mainly this feature and it is broken now :-/

veler commented 2 months ago

Hi there,

I got a fix ready here: https://github.com/DevToys-app/DevToys.Tools/pull/42

Thanks for your patience. I'm hoping to publish the fix this weekend or early next week.