diff --git a/modules/admin.js b/modules/admin.js index e9917c5..44f4dfc 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -304,7 +304,7 @@ app.post('/admin/other', async (req, res) => { const submissions = await JudgeState.find(); for (const s of submissions) { if (s.type !== 'submit-answer') { - s.code_length = s.code.length; + s.code_length = Buffer.from(s.code).length; await s.save(); } } diff --git a/modules/contest.js b/modules/contest.js index beee933..5d8786b 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -432,7 +432,7 @@ app.get('/contest/submission/:id', async (req, res) => { judge.problem.title = syzoj.utils.removeTitleTag(judge.problem.title); if (judge.problem.type !== 'submit-answer') { - judge.codeLength = judge.code.length; + judge.codeLength = Buffer.from(judge.code).length; judge.code = await syzoj.utils.highlight(judge.code, syzoj.languages[judge.language].highlight); } diff --git a/modules/problem.js b/modules/problem.js index 8b4e744..fd25b15 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -172,7 +172,7 @@ app.get('/problems/tag/:tagIDs', async (req, res) => { problem.allowedEdit = await problem.isAllowedEditBy(res.locals.user); problem.judge_state = await problem.getJudgeState(res.locals.user, true); problem.tags = await problem.getTags(); - + return problem; }); @@ -279,7 +279,7 @@ app.get('/problem/:id/edit', async (req, res) => { problem = await Problem.create({ time_limit: syzoj.config.default.problem.time_limit, memory_limit: syzoj.config.default.problem.memory_limit, - type: 'traditional' + type: 'traditional' }); problem.id = id; problem.allowedEdit = true; @@ -314,7 +314,7 @@ app.post('/problem/:id/edit', async (req, res) => { problem = await Problem.create({ time_limit: syzoj.config.default.problem.time_limit, memory_limit: syzoj.config.default.problem.memory_limit, - type: 'traditional' + type: 'traditional' }); if (await res.locals.user.hasPrivilege('manage_problem')) { @@ -381,7 +381,7 @@ app.get('/problem/:id/import', async (req, res) => { problem = await Problem.create({ time_limit: syzoj.config.default.problem.time_limit, memory_limit: syzoj.config.default.problem.memory_limit, - type: 'traditional' + type: 'traditional' }); problem.id = id; problem.new = true; @@ -415,7 +415,7 @@ app.post('/problem/:id/import', async (req, res) => { problem = await Problem.create({ time_limit: syzoj.config.default.problem.time_limit, memory_limit: syzoj.config.default.problem.memory_limit, - type: 'traditional' + type: 'traditional' }); if (await res.locals.user.hasPrivilege('manage_problem')) { @@ -646,7 +646,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1 if (req.files['answer'][0].size > syzoj.config.limit.submit_code) throw new ErrorMessage('代码文件太大。'); code = (await fs.readFile(req.files['answer'][0].path)).toString(); } else { - if (req.body.code.length > syzoj.config.limit.submit_code) throw new ErrorMessage('代码太长。'); + if (Buffer.from(req.body.code).length > syzoj.config.limit.submit_code) throw new ErrorMessage('代码太长。'); code = req.body.code; } @@ -655,7 +655,7 @@ app.post('/problem/:id/submit', app.multer.fields([{ name: 'answer', maxCount: 1 status: 'Unknown', task_id: randomstring.generate(10), code: code, - code_length: code.length, + code_length: Buffer.from(code).length, language: req.body.language, user_id: curUser.id, problem_id: req.params.id, @@ -930,7 +930,7 @@ app.post('/problem/:id/custom-test', app.multer.fields([{ name: 'code_upload', m if (req.files['code_upload'][0].size > syzoj.config.limit.submit_code) throw new ErrorMessage('代码过长。'); code = (await require('fs-extra').readFileAsync(req.files['code_upload'][0].path)).toString(); } else { - if (req.body.code.length > syzoj.config.limit.submit_code) throw new ErrorMessage('代码过长。'); + if (Buffer.from(req.body.code).length > syzoj.config.limit.submit_code) throw new ErrorMessage('代码过长。'); code = req.body.code; } diff --git a/modules/submission.js b/modules/submission.js index 74c4a2b..af58da2 100644 --- a/modules/submission.js +++ b/modules/submission.js @@ -110,7 +110,7 @@ app.get('/submissions', async (req, res) => { const judge_state = queryResult.data; await judge_state.forEachAsync(async obj => { await obj.loadRelationships(); - if (obj.problem.type !== 'submit-answer') obj.code_length = obj.code.length; + if (obj.problem.type !== 'submit-answer') obj.code_length = Buffer.from(obj.code).length; }); res.render('submissions', { @@ -160,7 +160,7 @@ app.get('/submission/:id', async (req, res) => { await judge.loadRelationships(); if (judge.problem.type !== 'submit-answer') { - judge.code_length = judge.code.length; + judge.code_length = Buffer.from(judge.code).length; let key = syzoj.utils.getFormattedCodeKey(judge.code, judge.language); if (key) {