Skip to content

Commit 8b8f26f

Browse files
FIX: allow rss feeds to have an enclosure with length of 0 (#9967)
* fix: allow rss feeds to have an enclosure with length of 0 * chore: add changeset * fix: typo on test * fix: update changeset description Co-authored-by: Florian Lefebvre <[email protected]> --------- Co-authored-by: Florian Lefebvre <[email protected]>
1 parent 57ab98f commit 8b8f26f

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

.changeset/tidy-spoons-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@astrojs/rss": patch
3+
---
4+
5+
Allows `enclosure' to have a length of 0

packages/astro-rss/src/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const rssSchema = z.object({
1616
enclosure: z
1717
.object({
1818
url: z.string(),
19-
length: z.number().positive().int().finite(),
19+
length: z.number().nonnegative().int().finite(),
2020
type: z.string(),
2121
})
2222
.optional(),

packages/astro-rss/test/rss.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,27 @@ describe('getRssString', () => {
227227
}
228228
chai.expect(error).to.be.null;
229229
});
230+
231+
it('should not fail when an enclosure has a length of 0', async () => {
232+
const str = await getRssString({
233+
title,
234+
description,
235+
items: [
236+
{
237+
title: 'Title',
238+
pubDate: new Date().toISOString(),
239+
description: 'Description',
240+
link: '/link',
241+
enclosure: {
242+
url: '/enclosure',
243+
length: 0,
244+
type: 'audio/mpeg',
245+
},
246+
},
247+
],
248+
site,
249+
});
250+
251+
chai.expect(str).to.not.throw;
252+
});
230253
});

0 commit comments

Comments
 (0)