Skip to content

Commit 62eb1a5

Browse files
committed
fix: unicode char display error
1 parent 7e11ad0 commit 62eb1a5

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

extensions/github1s/package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@
4040
},
4141
"commands": [
4242
{
43-
"command": "github1s.update-token",
44-
"title": "Update GitHub OAuth Token",
45-
"category": "GitHub1s"
46-
},
43+
"command": "github1s.update-token",
44+
"title": "Update GitHub OAuth Token",
45+
"category": "GitHub1s"
46+
},
4747
{
48-
"command": "github1s.validate-token",
49-
"title": "Validate Current GitHub OAuth Token",
50-
"category": "GitHub1s"
51-
},
48+
"command": "github1s.validate-token",
49+
"title": "Validate Current GitHub OAuth Token",
50+
"category": "GitHub1s"
51+
},
5252
{
53-
"command": "github1s.clear-token",
54-
"title": "Clear Current GitHub OAuth Token",
55-
"category": "GitHub1s"
56-
}
57-
]
53+
"command": "github1s.clear-token",
54+
"title": "Clear Current GitHub OAuth Token",
55+
"category": "GitHub1s"
56+
}
57+
]
5858
},
5959
"scripts": {
6060
"clean": "rm -rf dist out",

extensions/github1s/src/github1sfs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
FileType,
1616
Uri,
1717
} from 'vscode';
18-
import { noop, dirname, reuseable } from './util';
18+
import { noop, dirname, reuseable, b64DecodeUnicode} from './util';
1919
import { readGitHubDirectory, readGitHubFile } from './api';
2020

2121
export class File implements FileStat {
@@ -172,7 +172,7 @@ export class GitHub1sFS implements FileSystemProvider, Disposable {
172172

173173
const encoder = new TextEncoder();
174174
return readGitHubFile(uri, file.sha).then(blob => {
175-
file.data = encoder.encode(atob(blob.content));
175+
file.data = encoder.encode(b64DecodeUnicode(blob.content));
176176
return file.data;
177177
});
178178
})

extensions/github1s/src/util/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,11 @@ export const getWebviewOptions = (extensionUri: vscode.Uri): vscode.WebviewOptio
6666
localResourceRoots: [vscode.Uri.joinPath(extensionUri, 'assets')]
6767
};
6868
};
69+
70+
export const b64DecodeUnicode = (str) => {
71+
// https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings
72+
// Going backwards: from bytestream, to percent-encoding, to original string.
73+
return decodeURIComponent(atob(str).split('').map(function(c) {
74+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
75+
}).join(''));
76+
}

0 commit comments

Comments
 (0)