diff --git a/judgels-client/src/components/ProblemWorksheetCard/Programming/ProblemSubmissionEditor/ProblemSubmissionEditor.jsx b/judgels-client/src/components/ProblemWorksheetCard/Programming/ProblemSubmissionEditor/ProblemSubmissionEditor.jsx index 4dcf51cf5..25c645a76 100644 --- a/judgels-client/src/components/ProblemWorksheetCard/Programming/ProblemSubmissionEditor/ProblemSubmissionEditor.jsx +++ b/judgels-client/src/components/ProblemWorksheetCard/Programming/ProblemSubmissionEditor/ProblemSubmissionEditor.jsx @@ -12,6 +12,7 @@ import { getGradingLanguageEditorSubmissionHint, gradingLanguageNamesMap, } from '../../../../modules/api/gabriel/language.js'; +import { decodeBase64 } from '../../../../utils/base64'; import './ProblemSubmissionEditor.scss'; @@ -72,7 +73,7 @@ export function ProblemSubmissionEditor({ (skeletons || []).forEach(skeleton => { if (skeleton.languages.indexOf(defaultGradingLanguage) >= 0) { - initialValues.editor = atob(skeleton.content); + initialValues.editor = decodeBase64(skeleton.content); } }); diff --git a/judgels-client/src/components/SubmissionDetails/Programming/SubmissionDetails.jsx b/judgels-client/src/components/SubmissionDetails/Programming/SubmissionDetails.jsx index 96d97af92..64e302f9f 100644 --- a/judgels-client/src/components/SubmissionDetails/Programming/SubmissionDetails.jsx +++ b/judgels-client/src/components/SubmissionDetails/Programming/SubmissionDetails.jsx @@ -16,6 +16,7 @@ import { import { isInteractive, isOutputOnly } from '../../../modules/api/gabriel/engine'; import { DEFAULT_SOURCE_KEY } from '../../../modules/api/gabriel/submission'; import { VerdictCode } from '../../../modules/api/gabriel/verdict'; +import { decodeBase64 } from '../../../utils/base64'; import './SubmissionDetails.scss'; @@ -301,7 +302,7 @@ export function SubmissionDetails({ {key === DEFAULT_SOURCE_KEY ? '' : key + ': '} {submissionFiles[key].name} - {atob(submissionFiles[key].content)} + {decodeBase64(submissionFiles[key].content)} {verdict.code === VerdictCode.CE && details && diff --git a/judgels-client/src/utils/base64.js b/judgels-client/src/utils/base64.js new file mode 100644 index 000000000..099395b14 --- /dev/null +++ b/judgels-client/src/utils/base64.js @@ -0,0 +1,5 @@ +// https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem +export function decodeBase64(base64) { + const binString = atob(base64); + return new TextDecoder().decode(Uint8Array.from(binString, m => m.codePointAt(0))); +}