core: fix validator

pull/499/head
undefined 2 years ago
parent bc43b2fd4e
commit caf6ce058f

@ -629,7 +629,7 @@ export class ProblemEditHandler extends ProblemManageHandler {
@route('pid', Types.ProblemId) @route('pid', Types.ProblemId)
@post('title', Types.Title) @post('title', Types.Title)
@post('content', Types.Content) @post('content', Types.Content)
@post('pid', Types.ProblemId, true) @post('pid', Types.ProblemId, true, (i) => /^[a-zA-Z]+[a-zA-Z0-9]*$/i.test(i))
@post('hidden', Types.Boolean) @post('hidden', Types.Boolean)
@post('tag', Types.Content, true, null, parseCategory) @post('tag', Types.Content, true, null, parseCategory)
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true) @post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
@ -965,7 +965,7 @@ export class ProblemCreateHandler extends Handler {
@post('title', Types.Title) @post('title', Types.Title)
@post('content', Types.Content) @post('content', Types.Content)
@post('pid', Types.ProblemId, true) @post('pid', Types.ProblemId, true, (i) => /^[a-zA-Z]+[a-zA-Z0-9]*$/i.test(i))
@post('hidden', Types.Boolean) @post('hidden', Types.Boolean)
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true) @post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
@post('tag', Types.Content, true, null, parseCategory) @post('tag', Types.Content, true, null, parseCategory)

@ -37,6 +37,7 @@ export function deleteUserCache(udoc: User | Udoc | string | true | undefined |
for (const key of [...cache.keys()].filter((i) => i.endsWith(`/${udoc}`))) cache.delete(key); for (const key of [...cache.keys()].filter((i) => i.endsWith(`/${udoc}`))) cache.delete(key);
return true; return true;
} }
if (!udoc.uname) global.sendMessage?.(`user/delcache: ${JSON.stringify(udoc)}`);
const id = [`id/${udoc._id.toString()}`, `name/${udoc.uname.toLowerCase()}`, `mail/${udoc.mail.toLowerCase()}`]; const id = [`id/${udoc._id.toString()}`, `name/${udoc.uname.toLowerCase()}`, `mail/${udoc.mail.toLowerCase()}`];
for (const key of [...cache.keys()].filter((k) => id.includes(`${k.split('/')[0]}/${k.split('/')[1]}`))) { for (const key of [...cache.keys()].filter((k) => id.includes(`${k.split('/')[0]}/${k.split('/')[1]}`))) {
cache.delete(key); cache.delete(key);
@ -163,6 +164,7 @@ function handleMailLower(mail: string) {
async function initAndCache(udoc: Udoc, dudoc, scope: bigint = PERM.PERM_ALL) { async function initAndCache(udoc: Udoc, dudoc, scope: bigint = PERM.PERM_ALL) {
const res = await new User(udoc, dudoc, scope).init(); const res = await new User(udoc, dudoc, scope).init();
if (!dudoc) global.sendMessage?.(new Error().stack);
cache.set(`id/${udoc._id}/${dudoc.domainId}`, res); cache.set(`id/${udoc._id}/${dudoc.domainId}`, res);
cache.set(`name/${udoc.unameLower}/${dudoc.domainId}`, res); cache.set(`name/${udoc.unameLower}/${dudoc.domainId}`, res);
cache.set(`mail/${udoc.mailLower}/${dudoc.domainId}`, res); cache.set(`mail/${udoc.mailLower}/${dudoc.domainId}`, res);

@ -81,11 +81,11 @@ export const Types: Types = {
Key: saslprepString(/^[a-zA-Z0-9-_]+$/), Key: saslprepString(/^[a-zA-Z0-9-_]+$/),
/** @deprecated */ /** @deprecated */
Name: saslprepString(/^.{1,255}$/), Name: saslprepString(/^.{1,255}$/),
Filename: saslprepString(/^[^.\\/?#~]{1,255}$/, (i) => !['con', '.', '..'].includes(i)), Filename: saslprepString(/^[^\\/?#~!|*]{1,255}$/, (i) => !['con', '.', '..'].includes(i)),
UidOrName: saslprepString(/^(.{3,31}|[\u4e00-\u9fa5]{2}|-?[0-9]+)$/), UidOrName: saslprepString(/^(.{3,31}|[\u4e00-\u9fa5]{2}|-?[0-9]+)$/),
Username: saslprepString(/^(.{3,31}|[\u4e00-\u9fa5]{2})$/), Username: saslprepString(/^(.{3,31}|[\u4e00-\u9fa5]{2})$/),
Password: saslprepString(/^.{6,255}$/), Password: saslprepString(/^.{6,255}$/),
ProblemId: saslprepString(/^[a-zA-Z]+[a-zA-Z0-9]*$/i, () => true, (s) => (Number.isSafeInteger(+s) ? +s : s)), ProblemId: saslprepString(/^[a-zA-Z0-9]+$/i, () => true, (s) => (Number.isSafeInteger(+s) ? +s : s)),
Email: saslprepString(/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$/i), Email: saslprepString(/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$/i),
DomainId: saslprepString(/^[a-zA-Z][a-zA-Z0-9_]{3,31}$/), DomainId: saslprepString(/^[a-zA-Z][a-zA-Z0-9_]{3,31}$/),
Role: saslprepString(/^[_0-9A-Za-z\u4e00-\u9fa5]{1,31}$/i), Role: saslprepString(/^[_0-9A-Za-z\u4e00-\u9fa5]{1,31}$/i),

@ -8,6 +8,7 @@ import {
} from 'vj/utils'; } from 'vj/utils';
export default new AutoloadPage('omnibar', () => { export default new AutoloadPage('omnibar', () => {
if (document.documentElement.dataset.layout !== 'basic') return;
const $search = $(` const $search = $(`
<div class='omnibar' data-hotkey="esc:click" style="opacity:0;display:none;"> <div class='omnibar' data-hotkey="esc:click" style="opacity:0;display:none;">
<div class='omnibar-main'> <div class='omnibar-main'>

@ -109,7 +109,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
<Toolbar> <Toolbar>
{canUsePretest && ( {canUsePretest && (
<ToolbarButton <ToolbarButton
disabled={this.props.isPosting || this.props.isRunning || this.props.pretestWaitSec} disabled={this.props.isPosting || this.props.isRunning || !!this.props.pretestWaitSec}
className="scratchpad__toolbar__pretest" className="scratchpad__toolbar__pretest"
onClick={() => this.props.postPretest(this.props)} onClick={() => this.props.postPretest(this.props)}
data-global-hotkey="f9" data-global-hotkey="f9"
@ -123,7 +123,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
</ToolbarButton> </ToolbarButton>
)} )}
<ToolbarButton <ToolbarButton
disabled={this.props.isPosting || this.props.submitWaitSec} disabled={this.props.isPosting || !!this.props.submitWaitSec}
className="scratchpad__toolbar__submit" className="scratchpad__toolbar__submit"
onClick={() => this.props.postSubmit(this.props)} onClick={() => this.props.postSubmit(this.props)}
data-global-hotkey="f10" data-global-hotkey="f10"

Loading…
Cancel
Save