Skip to content

Commit

Permalink
fix(client): correctly decode unicode chars in submission details (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar authored Oct 16, 2023
1 parent e598242 commit a685692
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getGradingLanguageEditorSubmissionHint,
gradingLanguageNamesMap,
} from '../../../../modules/api/gabriel/language.js';
import { decodeBase64 } from '../../../../utils/base64';

import './ProblemSubmissionEditor.scss';

Expand Down Expand Up @@ -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);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -301,7 +302,7 @@ export function SubmissionDetails({
{key === DEFAULT_SOURCE_KEY ? '' : key + ': '} {submissionFiles[key].name}
</h5>
<SourceCode language={getGradingLanguageSyntaxHighlighterValue(gradingLanguage)}>
{atob(submissionFiles[key].content)}
{decodeBase64(submissionFiles[key].content)}
</SourceCode>
{verdict.code === VerdictCode.CE &&
details &&
Expand Down
5 changes: 5 additions & 0 deletions judgels-client/src/utils/base64.js
Original file line number Diff line number Diff line change
@@ -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)));
}

0 comments on commit a685692

Please sign in to comment.