mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: optimize regex for isValidPid
This commit is contained in:
3 files changed
+3
-3
No files matched your search
@@ -487,7 +487,7 @@ export class ProblemModel {
|
|||||||
let overridePid = null;
|
let overridePid = null;
|
||||||
|
|
||||||
const isValidPid = async (id: string) => {
|
const isValidPid = async (id: string) => {
|
||||||
if (!(/^[A-Za-z]+[0-9A-Za-z]*$/.test(id))) return false;
|
if (!(/^[A-Za-z][0-9A-Za-z]*$/.test(id))) return false;
|
||||||
const doc = await ProblemModel.get(domainId, id);
|
const doc = await ProblemModel.get(domainId, id);
|
||||||
if (doc) {
|
if (doc) {
|
||||||
if (!override) return false;
|
if (!override) return false;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class ImportHojHandler extends Handler {
|
|||||||
content.samples = examples.map((sample) => ([sample.input, sample.output]));
|
content.samples = examples.map((sample) => ([sample.input, sample.output]));
|
||||||
}
|
}
|
||||||
const isValidPid = async (id: string) => {
|
const isValidPid = async (id: string) => {
|
||||||
if (!(/^[A-Za-z]+[0-9A-Za-z]*$/.test(id))) return false;
|
if (!(/^[A-Za-z][0-9A-Za-z]*$/.test(id))) return false;
|
||||||
if (await ProblemModel.get(domainId, id)) return false;
|
if (await ProblemModel.get(domainId, id)) return false;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class ImportQduojHandler extends Handler {
|
|||||||
}, 'html');
|
}, 'html');
|
||||||
if (+pdoc.display_id) pdoc.display_id = `P${pdoc.display_id}`;
|
if (+pdoc.display_id) pdoc.display_id = `P${pdoc.display_id}`;
|
||||||
const isValidPid = async (id: string) => {
|
const isValidPid = async (id: string) => {
|
||||||
if (!(/^[A-Za-z]+[0-9A-Za-z]*$/.test(id))) return false;
|
if (!(/^[A-Za-z][0-9A-Za-z]*$/.test(id))) return false;
|
||||||
if (await ProblemModel.get(domainId, id)) return false;
|
if (await ProblemModel.get(domainId, id)) return false;
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user