Skip to content

Commit

Permalink
FIX: allow rss feeds to have an enclosure with length of 0 (#9967)
Browse files Browse the repository at this point in the history
* 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 <contact@florian-lefebvre.dev>

---------

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
  • Loading branch information
madcampos and florian-lefebvre authored Feb 4, 2024
1 parent 57ab98f commit 8b8f26f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tidy-spoons-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/rss": patch
---

Allows `enclosure' to have a length of 0
2 changes: 1 addition & 1 deletion packages/astro-rss/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const rssSchema = z.object({
enclosure: z
.object({
url: z.string(),
length: z.number().positive().int().finite(),
length: z.number().nonnegative().int().finite(),
type: z.string(),
})
.optional(),
Expand Down
23 changes: 23 additions & 0 deletions packages/astro-rss/test/rss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,27 @@ describe('getRssString', () => {
}
chai.expect(error).to.be.null;
});

it('should not fail when an enclosure has a length of 0', async () => {
const str = await getRssString({
title,
description,
items: [
{
title: 'Title',
pubDate: new Date().toISOString(),
description: 'Description',
link: '/link',
enclosure: {
url: '/enclosure',
length: 0,
type: 'audio/mpeg',
},
},
],
site,
});

chai.expect(str).to.not.throw;
});
});

0 comments on commit 8b8f26f

Please sign in to comment.