PSGitLab icon indicating copy to clipboard operation
PSGitLab copied to clipboard

Invalid Text Encoding in API

Open MVKozlov opened this issue 6 years ago • 3 comments

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)

MVKozlov avatar Apr 20 '18 08:04 MVKozlov

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.

ngetchell avatar May 11 '18 00:05 ngetchell

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
    }

MVKozlov avatar May 11 '18 06:05 MVKozlov

@ngetchell seems you missed my last comment - v3.0.1 still have a bug with pages2+

MVKozlov avatar Jun 25 '20 12:06 MVKozlov