Skip to content

Commit

Permalink
Correctly decode UTF-8 from Base64 (and also encode UTF-8 when sendin…
Browse files Browse the repository at this point in the history
…g to action functions)
  • Loading branch information
szschaler committed Jan 30, 2024
1 parent e2dccc0 commit 38d8973
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions platform/src/FileHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class FileHandler {
}


base64ToBytes(base64) {
const binString = window.atob(base64);
return Uint8Array.from(binString, (m) => m.codePointAt(0));
}

fetchFile(url, isPrivate){

if (isPrivate){
Expand All @@ -19,14 +24,17 @@ class FileHandler {
if (requestUrl != null) {
var xhr = new XMLHttpRequest();
xhr.open("GET", requestUrl, false);
xhr.setRequestHeader("Accept", "application/json; charset=UTF-8");
xhr.withCredentials = true;
xhr.send();

if (xhr.status === 200) {

let response = JSON.parse(xhr.responseText);

return { content: window.atob(response.data.content), sha: response.data.sha };

let contents = new TextDecoder().decode(this.base64ToBytes(response.data.content));

return { content: contents, sha: response.data.sha };

} else {
return null;
Expand Down
2 changes: 1 addition & 1 deletion platform/src/Utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function jsonRequest(url, json, useCredentials=false){
var xhr = new XMLHttpRequest();

xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
xhr.withCredentials = useCredentials;

xhr.onload = function () {
Expand Down

0 comments on commit 38d8973

Please sign in to comment.