Fixed plugin values which depended on the region settings of the computer (#1194)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-12 08:57:50 +01:00
1 parent 65d50de033
commit a1b493cb13
20 files changed
+397 -137

No files matched your search

@@ -1,3 +1,4 @@
using System.Globalization;
using System.Net;
using System.Text;
using System.Text.Json;
@@ -208,7 +209,11 @@ internal sealed class SearXNGSearchClient
private static string ReadNodeString(JsonNode? node) => node is null ? string.Empty : node.ToString().Trim();
private static bool TryGetScore(JsonObject result, out double score)
/// <remarks>
/// An instance may also send the score as text. It comes in the notation of JSON, so the region
/// settings of the computer must not read it: with a decimal comma, "0.75" would become 75.
/// </remarks>
internal static bool TryGetScore(JsonObject result, out double score)
{
score = double.MinValue;
if (!result.TryGetPropertyValue("score", out var scoreNode) || scoreNode is null)
@@ -219,7 +224,7 @@ internal sealed class SearXNGSearchClient
JsonValue value when value.TryGetValue<double>(out var doubleScore) => ReturnScore(doubleScore, out score),
JsonValue value when value.TryGetValue<decimal>(out var decimalScore) => ReturnScore((double)decimalScore, out score),
JsonValue value when value.TryGetValue<int>(out var intScore) => ReturnScore(intScore, out score),
_ => double.TryParse(scoreNode.ToString(), out var parsedScore) && ReturnScore(parsedScore, out score),
_ => double.TryParse(scoreNode.ToString(), NumberStyles.Float, CultureInfo.InvariantCulture, out var parsedScore) && ReturnScore(parsedScore, out score),
};
}
@@ -1,3 +1,5 @@
using System.Globalization;
namespace AIStudio.Tools.ToolCallingSystem;
internal static class ToolSettingsValueParser
@@ -7,7 +9,7 @@ internal static class ToolSettingsValueParser
if (!settingsValues.TryGetValue(key, out var value) || string.IsNullOrWhiteSpace(value))
return null;
return int.TryParse(value, out var parsedValue) && parsedValue > 0 ? parsedValue : null;
return int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedValue) && parsedValue > 0 ? parsedValue : null;
}
public static bool TryReadOptionalPositiveInt(
@@ -23,7 +25,7 @@ internal static class ToolSettingsValueParser
if (!settingsValues.TryGetValue(key, out var rawValue) || string.IsNullOrWhiteSpace(rawValue))
return true;
if (int.TryParse(rawValue, out var parsedValue) && parsedValue > 0)
if (int.TryParse(rawValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out var parsedValue) && parsedValue > 0)
{
value = parsedValue;
return true;