ngetchell / PSGitLab

An interface for administering GitLab from the PowerShell command line.
MIT License
72 stars 42 forks source link

Invalid Text Encoding in API #156

Open MVKozlov opened 6 years ago

MVKozlov commented 6 years ago

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@domain.com
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@domain.com
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)

ngetchell commented 6 years ago

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.

MVKozlov commented 6 years ago

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 commented 4 years ago

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