Skip to content

Commit 7d3e182

Browse files
authored
Merge pull request #193 from arduino/fix/utf-8-loading
Fixed UTF-8 file parsing while opening and transferring.
2 parents d52a5a8 + db98310 commit 7d3e182

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ui/arduino/store.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,14 +1209,18 @@ async function store(state, emitter) {
12091209
// load content and append it to the list of files to open
12101210
let file = null
12111211
if (selectedFile.source == 'board') {
1212+
// fileContent receives a raw buffer from loadFile()
12121213
const fileContent = await serialBridge.loadFile(
12131214
serialBridge.getFullPath(
12141215
state.boardNavigationRoot,
12151216
state.boardNavigationPath,
12161217
selectedFile.fileName
12171218
)
12181219
)
1219-
const bytesToSource = String.fromCharCode(...fileContent);
1220+
// we convert the buffer to a Uint8Array
1221+
const contentArray = new Uint8Array(fileContent);
1222+
// we feed the Uint8Array to the TextDecoder
1223+
const bytesToSource = new TextDecoder('utf-8').decode(contentArray);
12201224
file = createFile({
12211225
parentFolder: state.boardNavigationPath,
12221226
fileName: selectedFile.fileName,

0 commit comments

Comments
 (0)