Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b5304ae
Fix: Remove commas from numeric strings before conversion to prevent …
AbishekPonmudi Apr 21, 2025
9946284
Merge branch 'master' into patch-3
AbishekPonmudi Apr 22, 2025
1570669
Fix: Remove commas from numeric strings before conversion to prevent …
AbishekPonmudi Apr 22, 2025
82f8b7b
Fix: Remove AllowHexSpecifier in BigInteger parsing to support format…
AbishekPonmudi Apr 22, 2025
a66921a
Fix: Update BigInteger parsing to use Parse() and support thousands s…
AbishekPonmudi Apr 22, 2025
861177e
Fix: Update BigInteger parsing to use Parse() and support thousands s…
AbishekPonmudi Apr 22, 2025
8b0bf4e
Merge branch 'master' into patch-3
AbishekPonmudi Apr 24, 2025
ad2bde6
Fix: Remove commas from numeric strings before conversion to prevent …
AbishekPonmudi Apr 25, 2025
c2c1725
Remove commas from numeric strings before conversion to prevent casti…
AbishekPonmudi Apr 26, 2025
fd9cdc0
Fix: Remove commas from numeric strings before conversion to prevent …
AbishekPonmudi Apr 26, 2025
d76fcd3
Merge branch 'PowerShell:master' into patch-3
AbishekPonmudi Apr 28, 2025
1a4cc3f
Tests for BigInteger Parsing Across Cultures (#25396)
AbishekPonmudi Apr 28, 2025
c665f56
Tests for BigInteger Parsing Across Cultures (#25396)
AbishekPonmudi Apr 28, 2025
b461db9
Tests for BigInteger Parsing Across Cultures (#25396)
AbishekPonmudi Apr 28, 2025
ac4f844
Merge branch 'master' into patch-3
AbishekPonmudi May 2, 2025
15b60ec
Fix: Remove commas from numeric strings before conversion to prevent …
AbishekPonmudi May 5, 2025
332b9a1
Fix: Remove commas from numeric strings before conversion to prevent …
AbishekPonmudi May 5, 2025
fd3e07c
Fix: Remove commas from numeric strings before conversion to prevent …
AbishekPonmudi May 5, 2025
c3e8d41
Tests for BigInteger Parsing Across Cultures (PowerShell#25396)
AbishekPonmudi May 7, 2025
627c863
Merge branch 'master' into patch-3
AbishekPonmudi May 7, 2025
b5c28a3
Tests for BigInteger Parsing Across Cultures (PowerShell#25396)
AbishekPonmudi May 7, 2025
0fd3199
Merge branch 'master' into patch-3
AbishekPonmudi May 7, 2025
b9ca9fc
Tests for BigInteger Parsing Across Cultures (PowerShell#25396)
AbishekPonmudi May 7, 2025
010f04d
Tests for BigInteger Parsing Across Cultures (PowerShell#25396)
AbishekPonmudi May 7, 2025
e2bc432
Add Tests for BigInteger Parsing Across Cultures (#25396)
AbishekPonmudi May 8, 2025
c4a08ff
Delete test/powershell/engine/BigIntegerCultureHandling.test.ps1
AbishekPonmudi May 8, 2025
97ec872
Add Tests for BigInteger Parsing Across Cultures (#25396)
AbishekPonmudi May 8, 2025
c89ed59
Add Tests for BigInteger Parsing Across Cultures (#25396)
AbishekPonmudi May 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/System.Management.Automation/engine/LanguagePrimitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ public override object ConvertFrom(object sourceValue, Type destinationType, IFo
string sourceAsString = (string)LanguagePrimitives.ConvertTo(sourceValue, typeof(string), formatProvider);
return LanguagePrimitives.ConvertTo(sourceAsString, destinationType, formatProvider);
}

/// <summary>
/// Returns false, since this converter is not designed to be used to
/// convert from the type associated with the converted to other types.
Expand Down Expand Up @@ -2943,17 +2942,12 @@ 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;

if (resultType == typeof(BigInteger))
{
NumberStyles style = NumberStyles.Integer | NumberStyles.AllowThousands;

return BigInteger.Parse(strToConvert, style, NumberFormatInfo.InvariantInfo);
}

// Fallback conversion for regular numeric types.
return GetIntegerSystemConverter(resultType).ConvertFrom(strToConvert);
}
Expand Down
38 changes: 38 additions & 0 deletions test/powershell/engine/Api/LanguagePrimitive.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,42 @@ Describe "Language Primitive Tests" -Tags "CI" {
$test.TestHandlerReturnEnum() | Should -BeTrue
$test.TestHandlerReturnObject() | Should -BeTrue
}

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
}
}
Loading