PSGitLab
PSGitLab copied to clipboard
Invalid Text Encoding in API
1. Provide a general summary of the issue in the Title above
I don't know, if this is api or module problem, but seems any API request use wrong text encoding
2. Describe Your Environment
Operating System and PowerShell version: Windows 7SP1x64 PSv5.1 Gitlab-CE 10.6
3. Expected Behavior
Let assume You have some localized usernames in gitlab
PS > Get-GitLabUser
name : Козлов Максим
username : MKozlov
id : 2
is_admin : True
email : [email protected]
last_sign_in_at : 2018-04-19T09:59:21.045+03:00
4. Current Behavior
PS > Get-GitLabUser
name : Ðозлов ÐакÑим
username : MKozlov
id : 2
is_admin : True
email : [email protected]
last_sign_in_at : 2018-04-19T09:59:21.045+03:00
5. Possible Solution
--- QueryGitLabAPI.original Fri Apr 20 11:23:20 2018
+++ QueryGitLabAPI.modified Fri Apr 20 11:23:42 2018
@@ -42,7 +42,8 @@
Write-Verbose "URL: $($Request.URI)"
$webContent = Invoke-WebRequest @Request
$totalPages = ($webContent).Headers['X-Total-Pages'][0] -as [int]
- $Results = $webContent.Content | ConvertFrom-Json
+ $bytes = $webContent.Content.ToCharArray() | Foreach-Object{ [byte]$_ }
+ $Results = [Text.Encoding]::UTF8.GetString($bytes) | ConvertFrom-Json
for ($i=1; $i -lt $totalPages; $i++) {
$newRequest = $Request.PSObject.Copy()
$newRequest.URI = $newRequest.URI + "?&page=$($i+1)"
6. Context
Can't read any localized texts from gitlab (project namespace, user names, commits)
Thanks for the patch. There doesn't seem to produce any errors adding your code but please try version 2.6.1 to confirm that the issue is resolved.
there is another place for this patch, inside the cycle
for ($i=1; $i -lt $totalPages; $i++) {
$newRequest = $Request.PSObject.Copy()
$newRequest.URI = $newRequest.URI + "?&page=$($i+1)"
$bytes = (Invoke-WebRequest @newRequest).Content.ToCharArray() | Foreach-Object{ [byte]$_ }
$Results += [Text.Encoding]::UTF8.GetString($bytes) | ConvertFrom-Json
}
@ngetchell seems you missed my last comment - v3.0.1 still have a bug with pages2+