Skip to content

Commit f1ab75e

Browse files
author
CI Bot
committed
fix: use NaN check instead of || for history limit parsing
parseInt('0') || 50 evaluates to 50 because 0 is falsy. Use Number.isNaN to correctly distinguish missing/invalid input from an explicit zero (which gets clamped to 1 by Math.max).
1 parent 806784b commit f1ab75e

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/server/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ async function handler(req, res) {
212212
const { slug: rawSlug, limit: rawLimit } = query;
213213
if (!rawSlug) return send(res, 400, { error: 'slug required' });
214214
const slug = canonicalizeSlug(rawSlug);
215-
const limit = Math.max(1, Math.min(HISTORY_WALK_LIMIT, parseInt(rawLimit, 10) || 50));
215+
const parsed = parseInt(rawLimit, 10);
216+
const limit = Math.max(1, Math.min(HISTORY_WALK_LIMIT, Number.isNaN(parsed) ? 50 : parsed));
216217
return send(res, 200, await cms.getArticleHistory({ slug, limit }));
217218
} catch (err) {
218219
logError(err);

0 commit comments

Comments
 (0)