Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Invalid Text Encoding in API #156

Open
MVKozlov opened this issue Apr 20, 2018 · 3 comments
Open

Invalid Text Encoding in API #156

MVKozlov opened this issue Apr 20, 2018 · 3 comments
Assignees
Labels

Comments

@MVKozlov
Copy link

MVKozlov commented Apr 20, 2018

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 ngetchell added the bug label May 10, 2018
@ngetchell ngetchell self-assigned this May 10, 2018
@ngetchell
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants