Skip to content

Commit

Permalink
Merge pull request #52 from zkemail/regex_validation
Browse files Browse the repository at this point in the history
Regex validation
  • Loading branch information
javiersuweijie authored Oct 20, 2024
2 parents ae92f0e + 462229c commit 14d23ea
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
5 changes: 2 additions & 3 deletions packages/app/src/app/submit/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export const formSchema = z.object({
ctx.addIssue({ code: 'custom', message: 'Parts must be an array' });
return z.NEVER;
}

for (let i = 0; i < parsed.length; i++) {
const part = parsed[i];
if (typeof part !== 'object' || part === null) {
Expand All @@ -113,8 +112,8 @@ export const formSchema = z.object({
}
try {
// try to map and see if it works
getPrefixRegex(parsed)
return parsed
getPrefixRegex(parsed);
return parsed;
}
catch (e: any) {
ctx.addIssue({ code: 'custom', message: (e as Error).message })
Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/app/submit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export default function Submit() {
{
name: "handle",
location: "body",
parts: [
{ "is_public": false, "regex_def": "email was meant for @" },
{ "is_public": true, "regex_def": "(a-zA-Z0-9_)+" }
]
parts: JSON.stringify([
{ "is_public": false, "regex_def": "email was meant for @" },
{ "is_public": true, "regex_def": "(a-zA-Z0-9_)+" }
], null, 2)
}
],
externalInputs: []
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const Item = (props: {entry: Entry}) => {
<div className="w-full mt-2">
<a href={"/try/"+entry.slug}><Button className="mr-2" disabled={entry.status !== "COMPLETED"}>Try it out</Button></a>
<a href={"/api/download/"+entry.slug}><Button variant="outline" className="mr-2">Download Example Project</Button></a>
{(entry.status === "COMPLETED" && entry.withModal)&& <a href={"/api/download_zkey/"+entry.slug}><Button variant="link" className="mr-2">Download .zkey</Button></a>}
{(entry.status === "COMPLETED" && (!('withModal' in entry) || entry.withModal === true))&& <a href={"/api/download_zkey/"+entry.slug}><Button variant="link" className="mr-2">Download .zkey</Button></a>}
{/* <Button className="mr-2">Download Circuits Only</Button> */}
<ItemParameterDialog entry={entry}/>
</div>
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/lib/code-gen/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export function getPrefixRegex(parts: { is_public: boolean, regex_def: string }[
let prefixRegex = "";
for (let part of parts) {
if (!part.is_public) prefixRegex = prefixRegex + part.regex_def;
if (!part.is_public && !part.regex_def) throw new Error('Part has to have a nonempty regex with is_public = false')
else break;
}
if (!prefixRegex) throw new Error('Part has to have start with a regex that is_public = false in order to find it later')
if (!prefixRegex) throw new Error('Part has to have a regex with is_public = false in order to find it later')
return JSON.stringify(prefixRegex)
}

Expand Down

0 comments on commit 14d23ea

Please sign in to comment.