diff --git a/src/__tests__/atom1.spec.ts b/src/__tests__/atom1.spec.ts
index a13c7a6..0449dac 100644
--- a/src/__tests__/atom1.spec.ts
+++ b/src/__tests__/atom1.spec.ts
@@ -42,6 +42,28 @@ describe("atom 1.0", () => {
expect(actual).toContain(' {
+ const feed = new Feed({
+ title: "Feed Title",
+ id: "http://example.com/",
+ link: "http://example.com/",
+ updated,
+ });
+ feed.addCategory("Arts & Crafts");
+ feed.addItem({
+ title: "Hello World",
+ link: "http://example.org/2013/12/14",
+ date: updated,
+ category: [{ name: "R&D", scheme: "https://example.com/s?a=1&b=2" }],
+ });
+ const actual = feed.atom1();
+ // unlike a text node, xml-js does not escape `&` inside an attribute value,
+ // so it must be escaped before being handed to the serializer
+ expect(actual).toContain('');
+ expect(actual).toContain('');
+ expect(actual).not.toContain("Arts & Crafts");
+ });
+
it("should emit the default generator when none is provided", () => {
const feed = new Feed({ title: "Feed Title", id: "https://example.com/", link: "https://example.com/" });
expect(feed.atom1()).toContain("https://github.com/jpmonette/feed");
diff --git a/src/atom1.ts b/src/atom1.ts
index 3a6e3a9..bf70f75 100644
--- a/src/atom1.ts
+++ b/src/atom1.ts
@@ -82,7 +82,7 @@ export default (ins: Feed) => {
base.feed.category = [];
ins.categories.forEach((category: string) => {
- base.feed.category.push({ _attributes: { term: category } });
+ base.feed.category.push({ _attributes: { term: sanitize(category) } });
});
base.feed.contributor = [];
@@ -253,9 +253,9 @@ const formatCategory = (category: Category) => {
return {
_attributes: {
- label: name,
- scheme,
- term,
+ label: sanitize(name),
+ scheme: sanitize(scheme),
+ term: sanitize(term),
},
};
};