Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double escaping of & in Atom feed "self" URL #145

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/__tests__/__snapshots__/atom1.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`atom 1.0 should generate a valid feed 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
<feed xmlns=\\"http://www.w3.org/2005/Atom\\">
<id>http://example.com/</id>
<id>http://example.com/?link=sanitized&amp;value=4</id>
<title>Feed Title</title>
<updated>2013-07-13T23:00:00.000Z</updated>
<generator>https://github.com/jpmonette/feed</generator>
Expand All @@ -12,12 +12,12 @@ exports[`atom 1.0 should generate a valid feed 1`] = `
<email>[email protected]</email>
<uri>https://example.com/johndoe?link=sanitized&amp;value=2</uri>
</author>
<link rel=\\"alternate\\" href=\\"http://example.com/\\"/>
<link rel=\\"self\\" href=\\"http://example.com/sampleFeed.rss\\"/>
<link rel=\\"alternate\\" href=\\"http://example.com/?link=sanitized&amp;value=3\\"/>
<link rel=\\"self\\" href=\\"http://example.com/sampleFeed.rss?link=sanitized&amp;value=2\\"/>
<link rel=\\"hub\\" href=\\"wss://example.com/\\"/>
<subtitle>This is my personnal feed!</subtitle>
<logo>http://example.com/image.png</logo>
<icon>http://example.com/image.ico</icon>
<logo>http://example.com/image.png?link=sanitized&amp;value=6</logo>
<icon>http://example.com/image.ico?link=sanitized&amp;value=7</icon>
<rights>All rights reserved 2013, John Doe</rights>
<category term=\\"Technology\\"/>
<contributor>
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/__snapshots__/json.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ exports[`json 1 should generate a valid feed 1`] = `
"{
\\"version\\": \\"https://jsonfeed.org/version/1\\",
\\"title\\": \\"Feed Title\\",
\\"home_page_url\\": \\"http://example.com/\\",
\\"feed_url\\": \\"http://example.com/sampleFeed.json\\",
\\"home_page_url\\": \\"http://example.com/?link=sanitized&value=3\\",
\\"feed_url\\": \\"http://example.com/sampleFeed.json?link=sanitized&value=5\\",
\\"description\\": \\"This is my personnal feed!\\",
\\"icon\\": \\"http://example.com/image.png\\",
\\"icon\\": \\"http://example.com/image.png?link=sanitized&value=6\\",
\\"author\\": {
\\"name\\": \\"John Doe\\",
\\"url\\": \\"https://example.com/johndoe?link=sanitized&value=2\\"
Expand Down
24 changes: 12 additions & 12 deletions src/__tests__/__snapshots__/rss2.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`rss 2.0 should generate a valid feed 1`] = `
<rss version=\\"2.0\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\">
<channel>
<title>Feed Title</title>
<link>http://example.com/</link>
<link>http://example.com/?link=sanitized&amp;value=3</link>
<description>This is my personnal feed!</description>
<lastBuildDate>Sat, 13 Jul 2013 23:00:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
Expand All @@ -14,8 +14,8 @@ exports[`rss 2.0 should generate a valid feed 1`] = `
<ttl>60</ttl>
<image>
<title>Feed Title</title>
<url>http://example.com/image.png</url>
<link>http://example.com/</link>
<url>http://example.com/image.png?link=sanitized&amp;value=6</url>
<link>http://example.com/?link=sanitized&amp;value=3</link>
</image>
<copyright>All rights reserved 2013, John Doe</copyright>
<category>Technology</category>
Expand All @@ -42,7 +42,7 @@ exports[`rss 2.0 should generate a valid feed with audio 1`] = `
<rss version=\\"2.0\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\">
<channel>
<title>Feed Title</title>
<link>http://example.com/</link>
<link>http://example.com/?link=sanitized&amp;value=3</link>
<description>This is my personnal feed!</description>
<lastBuildDate>Sat, 13 Jul 2013 23:00:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
Expand All @@ -51,8 +51,8 @@ exports[`rss 2.0 should generate a valid feed with audio 1`] = `
<ttl>60</ttl>
<image>
<title>Feed Title</title>
<url>http://example.com/image.png</url>
<link>http://example.com/</link>
<url>http://example.com/image.png?link=sanitized&amp;value=6</url>
<link>http://example.com/?link=sanitized&amp;value=3</link>
</image>
<copyright>All rights reserved 2013, John Doe</copyright>
<category>Technology</category>
Expand Down Expand Up @@ -118,7 +118,7 @@ exports[`rss 2.0 should generate a valid feed with enclosure 1`] = `
<rss version=\\"2.0\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\">
<channel>
<title>Feed Title</title>
<link>http://example.com/</link>
<link>http://example.com/?link=sanitized&amp;value=3</link>
<description>This is my personnal feed!</description>
<lastBuildDate>Sat, 13 Jul 2013 23:00:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
Expand All @@ -127,8 +127,8 @@ exports[`rss 2.0 should generate a valid feed with enclosure 1`] = `
<ttl>60</ttl>
<image>
<title>Feed Title</title>
<url>http://example.com/image.png</url>
<link>http://example.com/</link>
<url>http://example.com/image.png?link=sanitized&amp;value=6</url>
<link>http://example.com/?link=sanitized&amp;value=3</link>
</image>
<copyright>All rights reserved 2013, John Doe</copyright>
<category>Technology</category>
Expand Down Expand Up @@ -181,7 +181,7 @@ exports[`rss 2.0 should generate a valid feed with image properties 1`] = `
<rss version=\\"2.0\\" xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\">
<channel>
<title>Feed Title</title>
<link>http://example.com/</link>
<link>http://example.com/?link=sanitized&amp;value=3</link>
<description>This is my personnal feed!</description>
<lastBuildDate>Sat, 13 Jul 2013 23:00:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
Expand All @@ -190,8 +190,8 @@ exports[`rss 2.0 should generate a valid feed with image properties 1`] = `
<ttl>60</ttl>
<image>
<title>Feed Title</title>
<url>http://example.com/image.png</url>
<link>http://example.com/</link>
<url>http://example.com/image.png?link=sanitized&amp;value=6</url>
<link>http://example.com/?link=sanitized&amp;value=3</link>
</image>
<copyright>All rights reserved 2013, John Doe</copyright>
<category>Technology</category>
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ export const published = new Date("Sat, 10 Jul 2013 23:00:00 GMT");
export const sampleFeed = new Feed({
title: "Feed Title",
description: "This is my personnal feed!",
link: "http://example.com/",
id: "http://example.com/",
feed: "http://example.com/sampleFeed.rss",
link: "http://example.com/?link=sanitized&value=3",
id: "http://example.com/?link=sanitized&value=4",
feed: "http://example.com/sampleFeed.rss?link=sanitized&value=2",
feedLinks: {
json: "http://example.com/sampleFeed.json",
json: "http://example.com/sampleFeed.json?link=sanitized&value=5",
},
language: "en",
ttl: 60,
image: "http://example.com/image.png",
favicon: "http://example.com/image.ico",
image: "http://example.com/image.png?link=sanitized&value=6",
favicon: "http://example.com/image.ico?link=sanitized&value=7",
copyright: "All rights reserved 2013, John Doe",
hub: "wss://example.com/",
updated, // optional, default = today
Expand Down
2 changes: 1 addition & 1 deletion src/atom1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default (ins: Feed) => {
}

// link (rel="self")
const atomLink = sanitize(options.feed || (options.feedLinks && options.feedLinks.atom));
const atomLink = options.feed || (options.feedLinks && options.feedLinks.atom);

if (atomLink) {
base.feed.link.push({ _attributes: { rel: "self", href: sanitize(atomLink) } });
Expand Down