Repository: featbit/featbit (language: python)

Issue:
[Bug]: User Key in ASCII charset.
### Contact Details

_No response_

### What happened?

User Key is converted to ASCII characters in the rollout algorithm. There would be a prob if User Key contains special characters

### To Reproduce

1. Go to...

### Expected behavior

_No response_

### Screenshots

_No response_

### Browsers

_No response_

### Additional context

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct


Discussion / hints:

Fix patch:
diff --git a/modules/back-end/src/Domain/Targeting/SplittingAlgorithm.cs b/modules/back-end/src/Domain/Targeting/SplittingAlgorithm.cs
index 128cea94a..fdb528469 100644
--- a/modules/back-end/src/Domain/Targeting/SplittingAlgorithm.cs
+++ b/modules/back-end/src/Domain/Targeting/SplittingAlgorithm.cs
@@ -30,7 +30,7 @@ public static bool IsInRollout(string key, double[] rollouts)
 
     public static double RolloutOfKey(string key)
     {
-        var hashedKey = Hasher.ComputeHash(Encoding.ASCII.GetBytes(key));
+        var hashedKey = Hasher.ComputeHash(Encoding.UTF8.GetBytes(key));
         var magicNumber = BitConverter.ToInt32(hashedKey, 0);
         var percentage = Math.Abs((double)magicNumber / int.MinValue);
 
diff --git a/modules/evaluation-server/src/Domain/Core/SplittingAlgorithm.cs b/modules/evaluation-server/src/Domain/Core/SplittingAlgorithm.cs
index e8542d9af..8cd77198e 100644
--- a/modules/evaluation-server/src/Domain/Core/SplittingAlgorithm.cs
+++ b/modules/evaluation-server/src/Domain/Core/SplittingAlgorithm.cs
@@ -30,7 +30,7 @@ public static bool IsInRollout(string key, double[] rollouts)
 
     public static double RolloutOfKey(string key)
     {
-        var hashedKey = Hasher.ComputeHash(Encoding.ASCII.GetBytes(key));
+        var hashedKey = Hasher.ComputeHash(Encoding.UTF8.GetBytes(key));
         var magicNumber = BitConverter.ToInt32(hashedKey, 0);
         var percentage = Math.Abs((double)magicNumber / int.MinValue);
 


Test patch:
diff --git a/modules/back-end/tests/Domain.UnitTests/Targeting/SplittingAlgorithmTests.cs b/modules/back-end/tests/Domain.UnitTests/Targeting/SplittingAlgorithmTests.cs
new file mode 100644
index 000000000..6ae4124ae
--- /dev/null
+++ b/modules/back-end/tests/Domain.UnitTests/Targeting/SplittingAlgorithmTests.cs
@@ -0,0 +1,15 @@
+using Domain.Targeting;
+
+namespace Domain.UnitTests.Targeting;
+
+public class SplittingAlgorithmTests
+{
+    [Theory]
+    [InlineData("test-value", 0.14653629204258323)]
+    [InlineData("qKPKh1S3FolC", 0.9105919692665339)]
+    [InlineData("3eacb184-2d79-49df-9ea7-edd4f10e4c6f", 0.08994403155520558)]
+    public void ReturnSameResultForAnGivenKey(string key, double value)
+    {
+        Assert.Equal(value, SplittingAlgorithm.RolloutOfKey(key));
+    }
+}
\ No newline at end of file
diff --git a/modules/evaluation-server/tests/Domain.UnitTests/Core/SplittingAlgorithmTest.cs b/modules/evaluation-server/tests/Domain.UnitTests/Core/SplittingAlgorithmTest.cs
new file mode 100644
index 000000000..b2b5d8bd6
--- /dev/null
+++ b/modules/evaluation-server/tests/Domain.UnitTests/Core/SplittingAlgorithmTest.cs
@@ -0,0 +1,15 @@
+using Domain.Core;
+
+namespace Domain.UnitTests.Core;
+
+public class SplittingAlgorithmTest
+{
+    [Theory]
+    [InlineData("test-value", 0.14653629204258323)]
+    [InlineData("qKPKh1S3FolC", 0.9105919692665339)]
+    [InlineData("3eacb184-2d79-49df-9ea7-edd4f10e4c6f", 0.08994403155520558)]
+    public void ReturnSameResultForAnGivenKey(string key, double value)
+    {
+        Assert.Equal(value, SplittingAlgorithm.RolloutOfKey(key));
+    }
+}
\ No newline at end of file