From f17d8a6fd5f4958531fa325a9b972786514da941 Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 15 Dec 2023 20:20:49 +0800 Subject: [PATCH] core: fix --- packages/hydrooj/src/handler/problem.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index cced852c1..6859e8584 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -399,10 +399,13 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler { // e.g. ![img](file://a.jpg) will navigate to ![img](./pid/file/a.jpg) if (!this.request.json || args[2]) { this.response.body.pdoc.content = this.response.body.pdoc.content - .replace(/file:\/\/([^ \n)\\"]+?)/g, (str) => { - const info = str.match(/file:\/\/([^ \n)\\"]+?)/); + .replace(/file:\/\/([^ \n)\\"]+)/g, (str: string) => { + const info = str.match(/file:\/\/([^ \n)\\"]+)/); const fileinfo = info[1]; - const filename = fileinfo.split('?')[0]; // remove querystring + let filename = fileinfo.split('?')[0]; // remove querystring + try { + filename = decodeURIComponent(filename); + } catch (e) { } if (!this.pdoc.additional_file?.find((i) => i.name === filename)) return str; if (!args[1]) return `./${this.pdoc.docId}/file/${fileinfo}`; return `./${this.pdoc.docId}/file/${fileinfo}${fileinfo.includes('?') ? '&' : '?'}tid=${args[1]}`;