From b5304aede23b99386519cde63faf60ed1baf8f1b Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Mon, 21 Apr 2025 21:15:14 +0530 Subject: [PATCH 01/22] Fix: Remove commas from numeric strings before conversion to prevent casting errors. --- .../engine/LanguagePrimitives.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index ed1dc189270..f4d078f7681 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -199,8 +199,14 @@ public override bool CanConvertFrom(object sourceValue, Type destinationType) /// When no conversion was possible. public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { - string sourceAsString = (string)LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider); + // Fix: Remove commas from numeric strings before conversion to prevent casting errors. + string sourceAsString = LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider) as string; + + if (sourceAsString != null){ + sourceAsString = sourceAsString.Replace(",", ""); // Remove commas before conversion + } return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); + } /// From 157066931940a489b078d720f82e0edd13dd8267 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Tue, 22 Apr 2025 12:21:51 +0530 Subject: [PATCH 02/22] Fix: Remove commas from numeric strings before conversion to prevent casting errors (#25396) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Issue Summary PowerShell fails to convert numeric strings with thousands separators (e.g., commas) to `[bigint]`, causing casting errors. This occurs because the `ConvertFrom()` method in `LanguagePrimitives.cs` doesn’t handle formatted numbers. ## Cause - The `ConvertTo()` method doesn’t remove thousands separators (e.g., `,` in en-US), leading to `BigInteger.Parse()` failures. - This affects scripts handling large numbers with separators. ## Solution Modify `ConvertFrom()` to: - Detect the culture-specific thousands separator. - Remove it before conversion. --- .../engine/LanguagePrimitives.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index f4d078f7681..ba46cc14ae5 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -202,9 +202,14 @@ public override object ConvertFrom(object sourceValue, Type destinationType, IFo // Fix: Remove commas from numeric strings before conversion to prevent casting errors. string sourceAsString = LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider) as string; - if (sourceAsString != null){ - sourceAsString = sourceAsString.Replace(",", ""); // Remove commas before conversion - } + if (sourceAsString != null){ + + string groupSeparator = formatProvider?.GetFormat(typeof(NumberFormatInfo)) is NumberFormatInfo nfi + ? nfi.NumberGroupSeparator + : CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator; + + sourceAsString = sourceAsString.Replace(groupSeparator, string.Empty); // Remove culture-specific group separator + } return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); } From 82f8b7b739e4c4d2002a53c16136c82e0a7cb494 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Tue, 22 Apr 2025 14:27:59 +0530 Subject: [PATCH 03/22] Fix: Remove AllowHexSpecifier in BigInteger parsing to support formatted numeric strings (#25396) --- .../engine/LanguagePrimitives.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index ba46cc14ae5..e386e2a05b7 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -2954,17 +2954,21 @@ private static object ConvertStringToInteger( return result; } - if (resultType == typeof(BigInteger)) - { - // Fallback for BigInteger: manual parsing using any common format. - NumberStyles style = NumberStyles.AllowLeadingSign - | NumberStyles.AllowDecimalPoint - | NumberStyles.AllowExponent - | NumberStyles.AllowHexSpecifier; - - return BigInteger.Parse(strToConvert, style, NumberFormatInfo.InvariantInfo); + if (resultType == typeof(BigInteger)) + { + // Adjust NumberStyles to remove AllowHexSpecifier for standard numeric parsing + NumberStyles style = NumberStyles.AllowLeadingSign + | NumberStyles.AllowDecimalPoint + | NumberStyles.AllowExponent; + BigInteger parsedValue; + + if (BigInteger.TryParse(strToConvert, style, NumberFormatInfo.InvariantInfo, out parsedValue)) + { + return parsedValue; + } + + throw new PSInvalidCastException("Failed to convert string to BigInteger."); } - // Fallback conversion for regular numeric types. return GetIntegerSystemConverter(resultType).ConvertFrom(strToConvert); } From a66921a37ac49538561aa583ccc55466d937a1b5 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Tue, 22 Apr 2025 19:05:18 +0530 Subject: [PATCH 04/22] Fix: Update BigInteger parsing to use Parse() and support thousands separators (#25396) --- .../engine/LanguagePrimitives.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index e386e2a05b7..26a2d68d7f3 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -2956,18 +2956,10 @@ private static object ConvertStringToInteger( if (resultType == typeof(BigInteger)) { - // Adjust NumberStyles to remove AllowHexSpecifier for standard numeric parsing - NumberStyles style = NumberStyles.AllowLeadingSign - | NumberStyles.AllowDecimalPoint - | NumberStyles.AllowExponent; + NumberStyles style = NumberStyles.Integer | NumberStyles.AllowThousands; BigInteger parsedValue; - if (BigInteger.TryParse(strToConvert, style, NumberFormatInfo.InvariantInfo, out parsedValue)) - { - return parsedValue; - } - - throw new PSInvalidCastException("Failed to convert string to BigInteger."); + return BigInteger.Parse(strToConvert, style, NumberFormatInfo.InvariantInfo); } // Fallback conversion for regular numeric types. return GetIntegerSystemConverter(resultType).ConvertFrom(strToConvert); From 861177e5c068c6cc86ee4fd6e41c9c6469ca5a23 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Tue, 22 Apr 2025 19:08:48 +0530 Subject: [PATCH 05/22] Fix: Update BigInteger parsing to use Parse() and support thousands separators (#25396) --- src/System.Management.Automation/engine/LanguagePrimitives.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 26a2d68d7f3..6efa073a88a 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -2957,7 +2957,6 @@ private static object ConvertStringToInteger( if (resultType == typeof(BigInteger)) { NumberStyles style = NumberStyles.Integer | NumberStyles.AllowThousands; - BigInteger parsedValue; return BigInteger.Parse(strToConvert, style, NumberFormatInfo.InvariantInfo); } From ad2bde6b5dd37d14878b606e9a583623e2c90dcd Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Fri, 25 Apr 2025 10:53:38 +0530 Subject: [PATCH 06/22] Fix: Remove commas from numeric strings before conversion to prevent casting errors (PowerShell#25396) --- src/System.Management.Automation/engine/LanguagePrimitives.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 6efa073a88a..f3e4d004443 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -199,7 +199,6 @@ public override bool CanConvertFrom(object sourceValue, Type destinationType) /// When no conversion was possible. public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { - // Fix: Remove commas from numeric strings before conversion to prevent casting errors. string sourceAsString = LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider) as string; if (sourceAsString != null){ From c2c1725e8985c2a8843cc9ddc664f840d28ea302 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Sat, 26 Apr 2025 09:14:52 +0530 Subject: [PATCH 07/22] Remove commas from numeric strings before conversion to prevent casting error (Powershell #25396) --- .../engine/LanguagePrimitives.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index f3e4d004443..71423a3d817 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -200,18 +200,14 @@ public override bool CanConvertFrom(object sourceValue, Type destinationType) public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { string sourceAsString = LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider) as string; - - if (sourceAsString != null){ - - string groupSeparator = formatProvider?.GetFormat(typeof(NumberFormatInfo)) is NumberFormatInfo nfi - ? nfi.NumberGroupSeparator - : CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator; - - sourceAsString = sourceAsString.Replace(groupSeparator, string.Empty); // Remove culture-specific group separator - } - return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); + + if (!string.IsNullOrEmpty(sourceAsString) && destinationType == typeof(BigInteger)) + { + return BigInteger.Parse(sourceAsString, NumberStyles.Integer | NumberStyles.AllowThousands, NumberFormatInfo.InvariantInfo); + } + return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); + } - } /// /// Returns false, since this converter is not designed to be used to From fd9cdc0aa47e01071519fa30d1fb5017a65c4d61 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Sat, 26 Apr 2025 18:24:56 +0530 Subject: [PATCH 08/22] Fix: Remove commas from numeric strings before conversion to prevent casting errors (#25396) --- src/System.Management.Automation/engine/LanguagePrimitives.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 71423a3d817..35a0e70b73d 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -207,8 +207,6 @@ public override object ConvertFrom(object sourceValue, Type destinationType, IFo } return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); } - - /// /// Returns false, since this converter is not designed to be used to /// convert from the type associated with the converted to other types. From 1a4cc3f295b3a9cb858b43c6474f97dae91db958 Mon Sep 17 00:00:00 2001 From: Abishekponmudi Date: Mon, 28 Apr 2025 18:55:26 +0530 Subject: [PATCH 09/22] Tests for BigInteger Parsing Across Cultures (#25396) --- .../engine/BigIntegerCultureHandling.test.ps1 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/powershell/engine/BigIntegerCultureHandling.test.ps1 diff --git a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 new file mode 100644 index 00000000000..aed36dafdd9 --- /dev/null +++ b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 @@ -0,0 +1,26 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { + + It 'Can convert formatted numbers using PowerShell type system' { + [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("en-US") + $formattedNumber = "1,000" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 1000 + } + + It 'Handles formatted numbers correctly in hi-IN culture' { + [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("hi-IN") + $formattedNumber = "1,00,000" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 100000 + } + + It 'Correctly parses large numbers with separators' { + [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("fr-FR") + $formattedNumber = "1 000" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 1000 + } +} From c665f5608f0305d67dac93d3aa09a67ad2dd50e7 Mon Sep 17 00:00:00 2001 From: Abishekponmudi Date: Mon, 28 Apr 2025 19:01:12 +0530 Subject: [PATCH 10/22] Tests for BigInteger Parsing Across Cultures (#25396) --- test/powershell/engine/BigIntegerCultureHandling.test.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 index aed36dafdd9..a3f878fa87e 100644 --- a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 +++ b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 @@ -19,7 +19,7 @@ Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { It 'Correctly parses large numbers with separators' { [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("fr-FR") - $formattedNumber = "1 000" + $formattedNumber = "1,0,0,0" $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) $convertedValue | Should -Be 1000 } From b461db9d2f48534c33d7e80bbfbb3aad88149d0c Mon Sep 17 00:00:00 2001 From: Abishekponmudi Date: Mon, 28 Apr 2025 19:29:03 +0530 Subject: [PATCH 11/22] Tests for BigInteger Parsing Across Cultures (#25396) --- .../engine/BigIntegerCultureHandling.test.ps1 | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 index a3f878fa87e..902e7f8d4d7 100644 --- a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 +++ b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 @@ -17,10 +17,21 @@ Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { $convertedValue | Should -Be 100000 } - It 'Correctly parses large numbers with separators' { - [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("fr-FR") - $formattedNumber = "1,0,0,0" + It 'Handles large comma-separated numbers that previously failed' { + $formattedNumber = "9223372036854775,807" $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - $convertedValue | Should -Be 1000 + $convertedValue | Should -Be 9223372036854775807 + } + + It 'Handles extremely large numbers to verify precision' { + $formattedNumber = "99999999999999999999999999999" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 99999999999999999999999999999 + } + + It 'Parses mixed separators correctly' { + $formattedNumber = "1,0000,00" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 1000000 } } From 15b60ece4a9691ee53fbb4e756c740c25b23c403 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Mon, 5 May 2025 10:44:38 +0530 Subject: [PATCH 12/22] Fix: Remove commas from numeric strings before conversion to prevent casting errors (PowerShell#25396) --- .../engine/LanguagePrimitives.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 35a0e70b73d..1647035d7dc 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -199,14 +199,9 @@ public override bool CanConvertFrom(object sourceValue, Type destinationType) /// When no conversion was possible. public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { - string sourceAsString = LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider) as string; - - if (!string.IsNullOrEmpty(sourceAsString) && destinationType == typeof(BigInteger)) - { - return BigInteger.Parse(sourceAsString, NumberStyles.Integer | NumberStyles.AllowThousands, NumberFormatInfo.InvariantInfo); - } - return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); - } + string sourceAsString = (string)LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider); + return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); + } /// /// Returns false, since this converter is not designed to be used to /// convert from the type associated with the converted to other types. From 332b9a1788f02f161d0b646b6a1b05a66467a946 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Mon, 5 May 2025 11:32:26 +0530 Subject: [PATCH 13/22] Fix: Remove commas from numeric strings before conversion to prevent casting errors (PowerShell#25396) --- src/System.Management.Automation/engine/LanguagePrimitives.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 1647035d7dc..9608820218a 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -199,8 +199,8 @@ public override bool CanConvertFrom(object sourceValue, Type destinationType) /// When no conversion was possible. public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { - string sourceAsString = (string)LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider); - return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); + string sourceAsString = LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider) as string; + return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); } /// /// Returns false, since this converter is not designed to be used to From fd3e07c1cea3cc530ab3261bdaac0b61f46a2e92 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Mon, 5 May 2025 11:49:11 +0530 Subject: [PATCH 14/22] Fix: Remove commas from numeric strings before conversion to prevent casting errors (PowerShell#25396) --- src/System.Management.Automation/engine/LanguagePrimitives.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 9608820218a..6644223d7c6 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -199,7 +199,7 @@ public override bool CanConvertFrom(object sourceValue, Type destinationType) /// When no conversion was possible. public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { - string sourceAsString = LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider) as string; + string sourceAsString = (string)LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider); return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider); } /// From c3e8d41d7c3103d2bbc63ebb9ac7b3ed2bdded77 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Wed, 7 May 2025 23:56:22 +0530 Subject: [PATCH 15/22] Tests for BigInteger Parsing Across Cultures (PowerShell#25396) --- .../engine/BigIntegerCultureHandling.test.ps1 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 index 902e7f8d4d7..0848692a199 100644 --- a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 +++ b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 @@ -34,4 +34,18 @@ Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) $convertedValue | Should -Be 1000000 } + + It 'Parses number using de-DE culture but falls back to invariant behavior' { + [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("de-DE") + $formattedNumber = "1.000" # in de-DE this means 1000 + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + # since [bigint] uses invariant culture, this will be parsed as 1 + $convertedValue | Should -Be 1 + } + + It 'Casts from floating-point number string to BigInteger using fallback' { + $formattedNumber = "1.2" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 1 + } } From b5c28a32f309a47b04c7a86188f2924261255358 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Thu, 8 May 2025 00:42:55 +0530 Subject: [PATCH 16/22] Tests for BigInteger Parsing Across Cultures (PowerShell#25396) --- .../engine/BigIntegerCultureHandling.test.ps1 | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 index 0848692a199..127bb0d0df0 100644 --- a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 +++ b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 @@ -10,13 +10,6 @@ Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { $convertedValue | Should -Be 1000 } - It 'Handles formatted numbers correctly in hi-IN culture' { - [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("hi-IN") - $formattedNumber = "1,00,000" - $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - $convertedValue | Should -Be 100000 - } - It 'Handles large comma-separated numbers that previously failed' { $formattedNumber = "9223372036854775,807" $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) @@ -36,11 +29,17 @@ Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { } It 'Parses number using de-DE culture but falls back to invariant behavior' { - [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("de-DE") - $formattedNumber = "1.000" # in de-DE this means 1000 - $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - # since [bigint] uses invariant culture, this will be parsed as 1 - $convertedValue | Should -Be 1 + $originalCulture = [cultureinfo]::CurrentCulture + try { + [cultureinfo]::CurrentCulture = [cultureinfo]::GetCultureInfo("de-DE") + $formattedNumber = "1.000" # in de-DE this means 1000 + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + # since [bigint] uses invariant culture, this will be parsed as 1 + $convertedValue | Should -Be 1 + } + finally { + [cultureinfo]::CurrentCulture = $originalCulture + } } It 'Casts from floating-point number string to BigInteger using fallback' { From b9ca9fcce7805774e4fc7089a3988a28c8439a70 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Thu, 8 May 2025 01:10:58 +0530 Subject: [PATCH 17/22] Tests for BigInteger Parsing Across Cultures (PowerShell#25396) --- test/powershell/engine/BigIntegerCultureHandling.test.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 index 127bb0d0df0..ade5a16dd5f 100644 --- a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 +++ b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 @@ -10,7 +10,7 @@ Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { $convertedValue | Should -Be 1000 } - It 'Handles large comma-separated numbers that previously failed' { + It 'Handles large numbers with thousands separators that previously failed' { $formattedNumber = "9223372036854775,807" $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) $convertedValue | Should -Be 9223372036854775807 @@ -28,7 +28,7 @@ Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { $convertedValue | Should -Be 1000000 } - It 'Parses number using de-DE culture but falls back to invariant behavior' { + It 'Parses a number string using the invariant culture, irrespective of the current culture' { $originalCulture = [cultureinfo]::CurrentCulture try { [cultureinfo]::CurrentCulture = [cultureinfo]::GetCultureInfo("de-DE") From 010f04dd5d8c739a495f94812b909b28ded4f6af Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Thu, 8 May 2025 01:19:22 +0530 Subject: [PATCH 18/22] Tests for BigInteger Parsing Across Cultures (PowerShell#25396) --- test/powershell/engine/BigIntegerCultureHandling.test.ps1 | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 index ade5a16dd5f..ce506ab175e 100644 --- a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 +++ b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 @@ -3,13 +3,6 @@ Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { - It 'Can convert formatted numbers using PowerShell type system' { - [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("en-US") - $formattedNumber = "1,000" - $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - $convertedValue | Should -Be 1000 - } - It 'Handles large numbers with thousands separators that previously failed' { $formattedNumber = "9223372036854775,807" $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) From e2bc432bd3cf9566dc969c0b478f78a2bfb04932 Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Thu, 8 May 2025 13:21:30 +0530 Subject: [PATCH 19/22] Add Tests for BigInteger Parsing Across Cultures (#25396) --- .../engine/Api/LanguagePrimitive.Tests.ps1 | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 b/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 index bc9d812afe4..18428c65ed0 100644 --- a/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 +++ b/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 @@ -185,4 +185,49 @@ Describe "Language Primitive Tests" -Tags "CI" { $test.TestHandlerReturnEnum() | Should -BeTrue $test.TestHandlerReturnObject() | Should -BeTrue } + + It 'Can convert formatted numbers using PowerShell type system' { + [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("en-US") + $formattedNumber = "1,000" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 1000 + } + + It 'Handles large numbers with thousands separators that previously failed' { + $formattedNumber = "9223372036854775,807" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 9223372036854775807 + } + + It 'Handles extremely large numbers to verify precision' { + $formattedNumber = "99999999999999999999999999999" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 99999999999999999999999999999 + } + + It 'Parses mixed separators correctly' { + $formattedNumber = "1,0000,00" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 1000000 + } + + It 'Parses a number string using the invariant culture, irrespective of the current culture' { + $originalCulture = [cultureinfo]::CurrentCulture + try { + [cultureinfo]::CurrentCulture = [cultureinfo]::GetCultureInfo("de-DE") + $formattedNumber = "1.000" # in de-DE this means 1000 + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + # since [bigint] uses invariant culture, this will be parsed as 1 + $convertedValue | Should -Be 1 + } + finally { + [cultureinfo]::CurrentCulture = $originalCulture + } + } + + It 'Casts from floating-point number string to BigInteger using fallback' { + $formattedNumber = "1.2" + $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) + $convertedValue | Should -Be 1 + } } From c4a08ffb237a710b6a0c83b7a38d495fbb4dffce Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Thu, 8 May 2025 13:22:20 +0530 Subject: [PATCH 20/22] Delete test/powershell/engine/BigIntegerCultureHandling.test.ps1 --- .../engine/BigIntegerCultureHandling.test.ps1 | 43 ------------------- 1 file changed, 43 deletions(-) delete mode 100644 test/powershell/engine/BigIntegerCultureHandling.test.ps1 diff --git a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 b/test/powershell/engine/BigIntegerCultureHandling.test.ps1 deleted file mode 100644 index ce506ab175e..00000000000 --- a/test/powershell/engine/BigIntegerCultureHandling.test.ps1 +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -Describe 'PowerShell Type Conversion - BigInteger Parsing' -Tag 'CI' { - - It 'Handles large numbers with thousands separators that previously failed' { - $formattedNumber = "9223372036854775,807" - $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - $convertedValue | Should -Be 9223372036854775807 - } - - It 'Handles extremely large numbers to verify precision' { - $formattedNumber = "99999999999999999999999999999" - $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - $convertedValue | Should -Be 99999999999999999999999999999 - } - - It 'Parses mixed separators correctly' { - $formattedNumber = "1,0000,00" - $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - $convertedValue | Should -Be 1000000 - } - - It 'Parses a number string using the invariant culture, irrespective of the current culture' { - $originalCulture = [cultureinfo]::CurrentCulture - try { - [cultureinfo]::CurrentCulture = [cultureinfo]::GetCultureInfo("de-DE") - $formattedNumber = "1.000" # in de-DE this means 1000 - $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - # since [bigint] uses invariant culture, this will be parsed as 1 - $convertedValue | Should -Be 1 - } - finally { - [cultureinfo]::CurrentCulture = $originalCulture - } - } - - It 'Casts from floating-point number string to BigInteger using fallback' { - $formattedNumber = "1.2" - $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - $convertedValue | Should -Be 1 - } -} From 97ec8725477746ff5ef5b5b8410e34d3d4c2f84e Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Thu, 8 May 2025 13:30:08 +0530 Subject: [PATCH 21/22] Add Tests for BigInteger Parsing Across Cultures (#25396) From c89ed5944c43aee0745682158ba996e5d8c5090d Mon Sep 17 00:00:00 2001 From: "(Havox)" <135835548+AbishekPonmudi@users.noreply.github.com> Date: Thu, 8 May 2025 15:21:25 +0530 Subject: [PATCH 22/22] Add Tests for BigInteger Parsing Across Cultures (#25396) --- test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 b/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 index 18428c65ed0..6149adc2ab7 100644 --- a/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 +++ b/test/powershell/engine/Api/LanguagePrimitive.Tests.ps1 @@ -185,14 +185,7 @@ Describe "Language Primitive Tests" -Tags "CI" { $test.TestHandlerReturnEnum() | Should -BeTrue $test.TestHandlerReturnObject() | Should -BeTrue } - - It 'Can convert formatted numbers using PowerShell type system' { - [System.Globalization.CultureInfo]::CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo("en-US") - $formattedNumber = "1,000" - $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint]) - $convertedValue | Should -Be 1000 - } - + It 'Handles large numbers with thousands separators that previously failed' { $formattedNumber = "9223372036854775,807" $convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint])