From e9b9338d7b20a83617b1a48e34604c870be695c1 Mon Sep 17 00:00:00 2001 From: pory-gone Date: Fri, 29 Aug 2025 19:34:11 +0200 Subject: [PATCH 1/3] Allow 0 and otherwise empty forwards --- lib/form.js | 7 ++++++- lib/validate.js | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/form.js b/lib/form.js index e3512907c5..1a6aa73977 100644 --- a/lib/form.js +++ b/lib/form.js @@ -10,7 +10,12 @@ export const normalizeForwards = (forward) => { if (!Array.isArray(forward)) { return undefined } - return forward.filter(fwd => fwd.nym || fwd.user?.name).map(fwd => ({ nym: fwd.nym ?? fwd.user?.name, pct: Number(fwd.pct) })) + // Convert to normalized objects and filter out entries with no recipient + // and entries with a zero/invalid percentage. Users sometimes type '0' + // to mean blank; treat those as empty and drop them before sending to the server. + return forward + .map(fwd => ({ nym: fwd.nym ?? fwd.user?.name, pct: Number(fwd.pct) })) + .filter(fwd => fwd.nym && Number.isFinite(fwd.pct) && fwd.pct > 0) } export const toastUpsertSuccessMessages = (toaster, upsertResponseData, dataKey, itemText) => { diff --git a/lib/validate.js b/lib/validate.js index ea1fa25c8f..ed71f3a15e 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -150,12 +150,20 @@ export function advPostSchemaMembers ({ me, existingBoost = 0, ...args }) { }, message: 'cannot forward to yourself' }), - pct: intValidator.required('must specify a percentage').min(1, 'percentage must be at least 1').max(100, 'percentage must not exceed 100') + pct: intValidator.required('must specify a percentage').max(100, 'percentage must not exceed 100') })) .compact((v) => !v.nym && !v.pct) .test({ name: 'sum', - test: forwards => forwards ? forwards.map(fwd => Number(fwd.pct)).reduce((sum, cur) => sum + cur, 0) <= 100 : true, + test: forwards => { + if (!forwards) return true + const pcts = forwards.map(fwd => { + const s = typeof fwd.pct === 'string' ? fwd.pct.trim() : fwd.pct + return s === '' ? NaN : parseFloat(s) + }) + if (!pcts.every(Number.isFinite)) return true + return pcts.reduce((sum, cur) => sum + cur, 0) <= 100 + }, message: 'the total forward percentage exceeds 100%' }) .test({ From ce523416a9d3df9d7873537a5f5ed20a2071ee11 Mon Sep 17 00:00:00 2001 From: pory-gone Date: Sat, 6 Sep 2025 14:24:11 +0200 Subject: [PATCH 2/3] implemented fix to validation logic t status echo "Status check" --- lib/validate.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/validate.js b/lib/validate.js index ed71f3a15e..4d4e052a53 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -4,7 +4,8 @@ import { MIN_POLL_NUM_CHOICES, MAX_FORWARDS, BOOST_MULT, MAX_TERRITORY_DESC_LENGTH, POST_TYPES, TERRITORY_BILLING_TYPES, MAX_COMMENT_TEXT_LENGTH, MAX_POST_TEXT_LENGTH, MIN_TITLE_LENGTH, BOUNTY_MIN, BOUNTY_MAX, RESERVED_SUB_NAMES, - BOOST_MAX + BOOST_MAX, + SSR } from './constants' import { SUPPORTED_CURRENCIES } from './currency' import { NOSTR_MAX_RELAY_NUM, NOSTR_PUBKEY_BECH32, NOSTR_PUBKEY_HEX } from './nostr' @@ -16,7 +17,7 @@ import { datePivot } from './time' export async function validateSchema (schema, data, args) { try { if (typeof schema === 'function') { - return await schema(args).validate(data) + return await schema({ server: SSR, ...args }).validate(data) } else { return await schema.validate(data) } @@ -120,7 +121,7 @@ export const searchSchema = object({ q: string().trim().max(100, 'must be at most 100 characters') }) -export function advPostSchemaMembers ({ me, existingBoost = 0, ...args }) { +export function advPostSchemaMembers ({ me, existingBoost = 0, server, ...args }) { const boostMin = existingBoost || BOOST_MIN return { boost: intValidator @@ -150,7 +151,9 @@ export function advPostSchemaMembers ({ me, existingBoost = 0, ...args }) { }, message: 'cannot forward to yourself' }), - pct: intValidator.required('must specify a percentage').max(100, 'percentage must not exceed 100') + pct: server + ? intValidator.required('must specify a percentage').min(1, 'percentage must be at least 1').max(100, 'percentage must not exceed 100') + : intValidator.required('must specify a percentage').max(100, 'percentage must not exceed 100') })) .compact((v) => !v.nym && !v.pct) .test({ From 90cc919f1837adb6cb55780a65644d5876127363 Mon Sep 17 00:00:00 2001 From: pory-gone Date: Mon, 8 Sep 2025 21:07:05 +0200 Subject: [PATCH 3/3] correct implementation --- lib/form.js | 2 +- lib/validate.js | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/form.js b/lib/form.js index 1a6aa73977..3fd0497162 100644 --- a/lib/form.js +++ b/lib/form.js @@ -15,7 +15,7 @@ export const normalizeForwards = (forward) => { // to mean blank; treat those as empty and drop them before sending to the server. return forward .map(fwd => ({ nym: fwd.nym ?? fwd.user?.name, pct: Number(fwd.pct) })) - .filter(fwd => fwd.nym && Number.isFinite(fwd.pct) && fwd.pct > 0) + .filter(fwd => fwd.nym && fwd.pct > 0) } export const toastUpsertSuccessMessages = (toaster, upsertResponseData, dataKey, itemText) => { diff --git a/lib/validate.js b/lib/validate.js index 4d4e052a53..9fa55420b3 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -158,15 +158,7 @@ export function advPostSchemaMembers ({ me, existingBoost = 0, server, ...args } .compact((v) => !v.nym && !v.pct) .test({ name: 'sum', - test: forwards => { - if (!forwards) return true - const pcts = forwards.map(fwd => { - const s = typeof fwd.pct === 'string' ? fwd.pct.trim() : fwd.pct - return s === '' ? NaN : parseFloat(s) - }) - if (!pcts.every(Number.isFinite)) return true - return pcts.reduce((sum, cur) => sum + cur, 0) <= 100 - }, + test: forwards => forwards ? forwards.map(fwd => Number(fwd.pct)).reduce((sum, cur) => sum + cur, 0) <= 100 : true, message: 'the total forward percentage exceeds 100%' }) .test({