From 2e7a8210bb7951014cc7b5d48fe700d701b0a1f5 Mon Sep 17 00:00:00 2001 From: jahooma Date: Wed, 26 Jan 2022 17:43:28 -0600 Subject: [PATCH] No symbols in fold primary tag. Limit Name to 140 chars --- functions/src/create-fold.ts | 4 +++- web/components/create-fold-button.tsx | 1 + web/lib/util/format.ts | 6 +++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/functions/src/create-fold.ts b/functions/src/create-fold.ts index 5d65e3de..b582760b 100644 --- a/functions/src/create-fold.ts +++ b/functions/src/create-fold.ts @@ -28,10 +28,12 @@ export const createFold = functions.runWith({ minInstances: 1 }).https.onCall( if (!name || typeof name !== 'string') return { status: 'error', message: 'Name must be a non-empty string' } + name = name.trim().slice(0, 140) + if (!about || typeof about !== 'string') return { status: 'error', message: 'About must be a non-empty string' } - about = about.slice(0, 140) + about = about.trim().slice(0, 140) if (!_.isArray(tags)) return { status: 'error', message: 'Tags must be an array of strings' } diff --git a/web/components/create-fold-button.tsx b/web/components/create-fold-button.tsx index ac9913c5..de4ff2d4 100644 --- a/web/components/create-fold-button.tsx +++ b/web/components/create-fold-button.tsx @@ -81,6 +81,7 @@ export function CreateFoldButton() { className="input input-bordered resize-none" disabled={isSubmitting} value={name} + maxLength={140} onChange={(e) => updateName(e.target.value || '')} /> diff --git a/web/lib/util/format.ts b/web/lib/util/format.ts index 741200c9..9b202d25 100644 --- a/web/lib/util/format.ts +++ b/web/lib/util/format.ts @@ -18,7 +18,7 @@ export function formatPercent(zeroToOne: number) { } export function toCamelCase(words: string) { - return words + const camelCase = words .split(' ') .map((word) => word.trim()) .filter((word) => word) @@ -26,4 +26,8 @@ export function toCamelCase(words: string) { index === 0 ? word : word[0].toLocaleUpperCase() + word.substring(1) ) .join('') + + // Remove non-alpha-numeric-underscore chars. + const regex = /(?:^|\s)(?:[a-z0-9_]+)/gi + return (camelCase.match(regex) || [])[0] ?? '' }