Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions .github/workflows/base64-source-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Base64String source compatibility
on:
push:
branches: [fix/base64-windows-padding, base64tring/develop]
pull_request:
branches: [base64tring/develop]
permissions:
contents: read
jobs:
source:
uses: stadub/PowershellScripts/.github/workflows/validate-release-candidate.yml@c5413b357e91d185c0e6698f776d83bd02131921
with:
module: Base64String
version: '1.2.0'
source_sha: ${{ github.event.pull_request.head.sha || github.sha }}
automation_sha: c5413b357e91d185c0e6698f776d83bd02131921
require_committed_package: false
3 changes: 3 additions & 0 deletions Shared-Functions/Base64String/Base64String.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ Describe 'Base64String encoding compatibility' {
@{ InputText = 'AAAAA' }
@{ InputText = 'Zg=' }
@{ InputText = 'Zm8==' }
@{ InputText = 'Zg======' }
@{ InputText = 'Zm9v====' }
@{ InputText = '====' }
@{ InputText = 'Zg===' }
@{ InputText = '=Zg=' }
@{ InputText = 'Z=g=' }
Expand Down
6 changes: 6 additions & 0 deletions Shared-Functions/Base64String/Base64String.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ Function ConvertFrom-Base64String {
3 { $normalized += '=' }
}
}
# .NET Framework accepts some over-padded input (for example Zm8==)
# that modern .NET rejects. Validate padding shape before either runtime.
if ($normalized.Contains('=') -and
($normalized.Length % 4 -ne 0 -or $normalized -cnotmatch '^[A-Za-z0-9+/]+={1,2}$')) {
throw (New-Object System.FormatException -ArgumentList 'Invalid Base64 length or padding.')
}
try {
$bytes = [System.Convert]::FromBase64String($normalized)
}
Expand Down
Loading