ignore negative maxItems

This commit is contained in:
shamoon
2026-09-24 16:35:33 -07:00
parent 4b8c5a91e7
commit 8d4a76c5bf
2 changed files with 12 additions and 1 deletions
+2 -1
View File
@@ -51,7 +51,8 @@ export default async function feedProxyHandler(req, res) {
cache.put(cacheKey, items, CACHE_MS);
}
const maxItems = parseInt(widget.maxItems, 10) || 5;
const limit = parseInt(widget.maxItems, 10);
const maxItems = limit > 0 ? limit : 5;
const showImages = widget.images !== false && widget.images !== "false";
return res.status(200).json({
+10
View File
@@ -79,6 +79,16 @@ describe("widgets/feed/proxy", () => {
});
});
it.each([-1, 0, "abc"])("falls back to 5 items for maxItems %j", async (maxItems) => {
getServiceWidget.mockResolvedValue({ type: "feed", url: "https://example.com/feed.xml", maxItems });
httpProxy.mockResolvedValueOnce([200, "application/rss+xml", Buffer.from(feed)]);
const res = createMockRes();
await feedProxyHandler(req, res);
expect(res.body.items).toHaveLength(5);
});
it("respects maxItems and drops images when disabled", async () => {
getServiceWidget.mockResolvedValue({
type: "feed",