File tree 1 file changed +43
-4
lines changed
arduino-ide-extension/src/browser/create
1 file changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,47 @@ export namespace ResponseResultProvider {
15
15
export const JSON : ResponseResultProvider = ( response ) => response . json ( ) ;
16
16
}
17
17
18
+ export function Utf8ArrayToStr ( array : Uint8Array ) : string {
19
+ let out , i , c ;
20
+ let char2 , char3 ;
21
+
22
+ out = '' ;
23
+ const len = array . length ;
24
+ i = 0 ;
25
+ while ( i < len ) {
26
+ c = array [ i ++ ] ;
27
+ switch ( c >> 4 ) {
28
+ case 0 :
29
+ case 1 :
30
+ case 2 :
31
+ case 3 :
32
+ case 4 :
33
+ case 5 :
34
+ case 6 :
35
+ case 7 :
36
+ // 0xxxxxxx
37
+ out += String . fromCharCode ( c ) ;
38
+ break ;
39
+ case 12 :
40
+ case 13 :
41
+ // 110x xxxx 10xx xxxx
42
+ char2 = array [ i ++ ] ;
43
+ out += String . fromCharCode ( ( ( c & 0x1f ) << 6 ) | ( char2 & 0x3f ) ) ;
44
+ break ;
45
+ case 14 :
46
+ // 1110 xxxx 10xx xxxx 10xx xxxx
47
+ char2 = array [ i ++ ] ;
48
+ char3 = array [ i ++ ] ;
49
+ out += String . fromCharCode (
50
+ ( ( c & 0x0f ) << 12 ) | ( ( char2 & 0x3f ) << 6 ) | ( ( char3 & 0x3f ) << 0 )
51
+ ) ;
52
+ break ;
53
+ }
54
+ }
55
+
56
+ return out ;
57
+ }
58
+
18
59
type ResourceType = 'f' | 'd' ;
19
60
20
61
@injectable ( )
@@ -275,9 +316,7 @@ export class CreateApi {
275
316
276
317
// parse the secret file
277
318
const secrets = (
278
- typeof content === 'string'
279
- ? content
280
- : new TextDecoder ( ) . decode ( content )
319
+ typeof content === 'string' ? content : Utf8ArrayToStr ( content )
281
320
)
282
321
. split ( / \r ? \n / )
283
322
. reduce ( ( prev , curr ) => {
@@ -341,7 +380,7 @@ export class CreateApi {
341
380
const headers = await this . headers ( ) ;
342
381
343
382
let data : string =
344
- typeof content === 'string' ? content : new TextDecoder ( ) . decode ( content ) ;
383
+ typeof content === 'string' ? content : Utf8ArrayToStr ( content ) ;
345
384
data = await this . toggleSecretsInclude ( posixPath , data , 'remove' ) ;
346
385
347
386
const payload = { data : btoa ( data ) } ;
You can’t perform that action at this time.
0 commit comments