Skip to content

Commit 9175584

Browse files
committed
feat: add UTF-8 encoding for file paths in SubmissionUploadForm
1 parent ebb3147 commit 9175584

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

components/submissions/submission-upload-form.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ interface SubmissionUploadFormProps {
2525

2626
const fetcher = (url: string) => api.get(url).then(res => res.data.data);
2727

28+
function btoaUTF8(str: string) {
29+
const bytes = new TextEncoder().encode(str);
30+
let binary = "";
31+
bytes.forEach(b => binary += String.fromCharCode(b));
32+
return btoa(binary);
33+
}
34+
2835
function AttemptsCounter({ problemId, onLimitReached }: { problemId: string, onLimitReached: (isReached: boolean) => void }) {
2936
const { data: attempts, isLoading } = useSWR<Attempts>(`/problems/${problemId}/attempts`, fetcher, {
3037
onSuccess: (data) => {
@@ -177,7 +184,7 @@ export default function SubmissionUploadForm({ problemId, uploadLimits }: Submis
177184
const formData = new FormData();
178185
filesToSubmit.forEach(file => {
179186
const filePath = (file as FileWithPath).path || (file as any).webkitRelativePath || file.name;
180-
formData.append('files', file, filePath);
187+
formData.append('files', file, btoaUTF8(filePath));
181188
});
182189

183190
try {

0 commit comments

Comments
 (0)