Skip to content

Commit 267d4a2

Browse files
committed
Remove default Encoding parameter values for future extensibility
Move encoding defaults from parameter declarations to internal handling: - Allows detection of whether user explicitly specified an encoding - Enables future best-effort improvements when encoding is not provided - All functions now use internal 'if ([string]::IsNullOrEmpty(\)) { \ = ''UTF8'' }' Updated functions: - ConvertFrom-Base64, ConvertFrom-MemoryStream, ConvertFrom-MemoryStreamToString - ConvertFrom-MemoryStreamToSecureString, ConvertFrom-StringToBase64 - ConvertFrom-StringToByteArray, ConvertFrom-StringToCompressedByteArray - ConvertFrom-StringToMemoryStream, ConvertTo-Base64, ConvertTo-Hash - ConvertTo-HmacHash, ConvertTo-MemoryStream
1 parent 4c643fb commit 267d4a2

13 files changed

Lines changed: 64 additions & 14 deletions

src/Convert/Public/ConvertFrom-Base64.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function ConvertFrom-Base64 {
7272
[Parameter(ParameterSetName = 'ToString')]
7373
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
7474
[String]
75-
$Encoding = 'UTF8',
75+
$Encoding,
7676

7777
[Parameter(ParameterSetName = 'ToString')]
7878
[Parameter(Mandatory = $false)]
@@ -88,6 +88,10 @@ function ConvertFrom-Base64 {
8888
begin {
8989
$userErrorActionPreference = $ErrorActionPreference
9090
$nullPtr = [IntPtr]::Zero
91+
# Default to UTF8 if no encoding specified
92+
if ([string]::IsNullOrEmpty($Encoding)) {
93+
$Encoding = 'UTF8'
94+
}
9195
}
9296

9397
process {

src/Convert/Public/ConvertFrom-MemoryStream.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function ConvertFrom-MemoryStream {
158158

159159
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
160160
[String]
161-
$Encoding = 'UTF8',
161+
$Encoding,
162162

163163
[Parameter(ParameterSetName = 'ToString')]
164164
[Switch]
@@ -171,6 +171,10 @@ function ConvertFrom-MemoryStream {
171171

172172
begin {
173173
$userErrorActionPreference = $ErrorActionPreference
174+
# Default to UTF8 if no encoding specified
175+
if ([string]::IsNullOrEmpty($Encoding)) {
176+
$Encoding = 'UTF8'
177+
}
174178
}
175179

176180
process {

src/Convert/Public/ConvertFrom-MemoryStreamToSecureString.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ function ConvertFrom-MemoryStreamToSecureString {
5656

5757
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
5858
[String]
59-
$Encoding = 'UTF8'
59+
$Encoding
6060
)
6161

6262
begin {
6363
$userErrorActionPreference = $ErrorActionPreference
64+
# Default to UTF8 if no encoding specified
65+
if ([string]::IsNullOrEmpty($Encoding)) {
66+
$Encoding = 'UTF8'
67+
}
6468
}
6569

6670
process {

src/Convert/Public/ConvertFrom-MemoryStreamToString.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,15 @@ function ConvertFrom-MemoryStreamToString {
9494

9595
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
9696
[String]
97-
$Encoding = 'UTF8'
97+
$Encoding
9898
)
9999

100100
begin {
101101
$userErrorActionPreference = $ErrorActionPreference
102+
# Default to UTF8 if no encoding specified
103+
if ([string]::IsNullOrEmpty($Encoding)) {
104+
$Encoding = 'UTF8'
105+
}
102106
}
103107

104108
process {

src/Convert/Public/ConvertFrom-StringToBase64.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function ConvertFrom-StringToBase64 {
7272

7373
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
7474
[String]
75-
$Encoding = 'UTF8',
75+
$Encoding,
7676

7777
[Parameter(Mandatory = $false)]
7878
[Switch]
@@ -82,6 +82,10 @@ function ConvertFrom-StringToBase64 {
8282
begin {
8383
$userErrorActionPreference = $ErrorActionPreference
8484
$nullPtr = [IntPtr]::Zero
85+
# Default to UTF8 if no encoding specified
86+
if ([string]::IsNullOrEmpty($Encoding)) {
87+
$Encoding = 'UTF8'
88+
}
8589
}
8690

8791
process {

src/Convert/Public/ConvertFrom-StringToByteArray.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ function ConvertFrom-StringToByteArray {
6666

6767
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
6868
[String]
69-
$Encoding = 'UTF8'
69+
$Encoding
7070
)
7171

7272
begin {
7373
$userErrorActionPreference = $ErrorActionPreference
74+
# Default to UTF8 if no encoding specified
75+
if ([string]::IsNullOrEmpty($Encoding)) {
76+
$Encoding = 'UTF8'
77+
}
7478
}
7579

7680
process {

src/Convert/Public/ConvertFrom-StringToCompressedByteArray.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ function ConvertFrom-StringToCompressedByteArray {
4747

4848
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
4949
[String]
50-
$Encoding = 'UTF8'
50+
$Encoding
5151
)
5252

5353
begin {
5454
$userErrorActionPreference = $ErrorActionPreference
5555
$nullPtr = [IntPtr]::Zero
56+
# Default to UTF8 if no encoding specified
57+
if ([string]::IsNullOrEmpty($Encoding)) {
58+
$Encoding = 'UTF8'
59+
}
5660
}
5761

5862
process {

src/Convert/Public/ConvertFrom-StringToMemoryStream.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,18 @@ function ConvertFrom-StringToMemoryStream {
9191

9292
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
9393
[String]
94-
$Encoding = 'UTF8',
94+
$Encoding,
9595

9696
[Switch]
9797
$Compress
9898
)
9999

100100
begin {
101101
$userErrorActionPreference = $ErrorActionPreference
102+
# Default to UTF8 if no encoding specified
103+
if ([string]::IsNullOrEmpty($Encoding)) {
104+
$Encoding = 'UTF8'
105+
}
102106
}
103107

104108
process {

src/Convert/Public/ConvertTo-Base64.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function ConvertTo-Base64 {
164164

165165
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
166166
[String]
167-
$Encoding = 'UTF8',
167+
$Encoding,
168168

169169
[Parameter(Mandatory = $false)]
170170
[Switch]
@@ -173,6 +173,10 @@ function ConvertTo-Base64 {
173173

174174
begin {
175175
$userErrorActionPreference = $ErrorActionPreference
176+
# Default to UTF8 if no encoding specified
177+
if ([string]::IsNullOrEmpty($Encoding)) {
178+
$Encoding = 'UTF8'
179+
}
176180

177181
$convertSplat = @{
178182
ErrorAction = $userErrorActionPreference

src/Convert/Public/ConvertTo-Hash.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ function ConvertTo-Hash {
3232

3333
[ValidateSet('ASCII', 'BigEndianUnicode', 'Default', 'Unicode', 'UTF32', 'UTF8')]
3434
[String]
35-
$Encoding = 'UTF8'
35+
$Encoding
3636
)
3737

3838
begin {
3939
$userErrorActionPreference = $ErrorActionPreference
4040
$nullPtr = [IntPtr]::Zero
41+
# Default to UTF8 if no encoding specified
42+
if ([string]::IsNullOrEmpty($Encoding)) {
43+
$Encoding = 'UTF8'
44+
}
4145
}
4246

4347
process {

0 commit comments

Comments
 (0)