Browse Source

Use byte count instead of character count for code length

pull/6/head
Menci 6 years ago
parent
commit
9f5ba6770d
  1. 2
      modules/admin.js
  2. 2
      modules/contest.js
  3. 6
      modules/problem.js
  4. 4
      modules/submission.js

2
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();
}
}

2
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);
}

6
modules/problem.js

@ -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;
}

4
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) {

Loading…
Cancel
Save