From 0aba08151b09ef159b49f282e4099b57f98e2b13 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Fri, 5 Mar 2021 22:09:09 +0100 Subject: [PATCH 1/3] Test for correct escaping of & in Atom feed "self" URL sanitization, currently fails. --- src/__tests__/__snapshots__/atom1.spec.ts.snap | 2 +- src/__tests__/setup.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/__tests__/__snapshots__/atom1.spec.ts.snap b/src/__tests__/__snapshots__/atom1.spec.ts.snap index 569cf1d..71aadab 100644 --- a/src/__tests__/__snapshots__/atom1.spec.ts.snap +++ b/src/__tests__/__snapshots__/atom1.spec.ts.snap @@ -13,7 +13,7 @@ exports[`atom 1.0 should generate a valid feed 1`] = ` https://example.com/johndoe?link=sanitized&value=2 - + This is my personnal feed! http://example.com/image.png diff --git a/src/__tests__/setup.ts b/src/__tests__/setup.ts index 79d77f7..02c333b 100644 --- a/src/__tests__/setup.ts +++ b/src/__tests__/setup.ts @@ -8,7 +8,7 @@ export const sampleFeed = new Feed({ description: "This is my personnal feed!", link: "http://example.com/", id: "http://example.com/", - feed: "http://example.com/sampleFeed.rss", + feed: "http://example.com/sampleFeed.rss?link=sanitized&value=2", feedLinks: { json: "http://example.com/sampleFeed.json", }, From 0a0dafdbfb384015b1d0fd7ca096298dab56fb0f Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Fri, 5 Mar 2021 22:12:12 +0100 Subject: [PATCH 2/3] Test for escaping of & in some more URLs. These currently succeed. --- .../__snapshots__/atom1.spec.ts.snap | 8 +++---- src/__tests__/__snapshots__/json.spec.ts.snap | 6 ++--- src/__tests__/__snapshots__/rss2.spec.ts.snap | 24 +++++++++---------- src/__tests__/setup.ts | 10 ++++---- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/__tests__/__snapshots__/atom1.spec.ts.snap b/src/__tests__/__snapshots__/atom1.spec.ts.snap index 71aadab..3fd7e50 100644 --- a/src/__tests__/__snapshots__/atom1.spec.ts.snap +++ b/src/__tests__/__snapshots__/atom1.spec.ts.snap @@ -3,7 +3,7 @@ exports[`atom 1.0 should generate a valid feed 1`] = ` " - http://example.com/ + http://example.com/?link=sanitized&value=4 Feed Title 2013-07-13T23:00:00.000Z https://github.com/jpmonette/feed @@ -12,12 +12,12 @@ exports[`atom 1.0 should generate a valid feed 1`] = ` johndoe@example.com https://example.com/johndoe?link=sanitized&value=2 - + This is my personnal feed! - http://example.com/image.png - http://example.com/image.ico + http://example.com/image.png?link=sanitized&value=6 + http://example.com/image.ico?link=sanitized&value=7 All rights reserved 2013, John Doe diff --git a/src/__tests__/__snapshots__/json.spec.ts.snap b/src/__tests__/__snapshots__/json.spec.ts.snap index 985e696..0f235cd 100644 --- a/src/__tests__/__snapshots__/json.spec.ts.snap +++ b/src/__tests__/__snapshots__/json.spec.ts.snap @@ -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\\" diff --git a/src/__tests__/__snapshots__/rss2.spec.ts.snap b/src/__tests__/__snapshots__/rss2.spec.ts.snap index 6cb59bc..50b4f8c 100644 --- a/src/__tests__/__snapshots__/rss2.spec.ts.snap +++ b/src/__tests__/__snapshots__/rss2.spec.ts.snap @@ -5,7 +5,7 @@ exports[`rss 2.0 should generate a valid feed 1`] = ` Feed Title - http://example.com/ + http://example.com/?link=sanitized&value=3 This is my personnal feed! Sat, 13 Jul 2013 23:00:00 GMT https://validator.w3.org/feed/docs/rss2.html @@ -14,8 +14,8 @@ exports[`rss 2.0 should generate a valid feed 1`] = ` 60 Feed Title - http://example.com/image.png - http://example.com/ + http://example.com/image.png?link=sanitized&value=6 + http://example.com/?link=sanitized&value=3 All rights reserved 2013, John Doe Technology @@ -42,7 +42,7 @@ exports[`rss 2.0 should generate a valid feed with audio 1`] = ` Feed Title - http://example.com/ + http://example.com/?link=sanitized&value=3 This is my personnal feed! Sat, 13 Jul 2013 23:00:00 GMT https://validator.w3.org/feed/docs/rss2.html @@ -51,8 +51,8 @@ exports[`rss 2.0 should generate a valid feed with audio 1`] = ` 60 Feed Title - http://example.com/image.png - http://example.com/ + http://example.com/image.png?link=sanitized&value=6 + http://example.com/?link=sanitized&value=3 All rights reserved 2013, John Doe Technology @@ -118,7 +118,7 @@ exports[`rss 2.0 should generate a valid feed with enclosure 1`] = ` Feed Title - http://example.com/ + http://example.com/?link=sanitized&value=3 This is my personnal feed! Sat, 13 Jul 2013 23:00:00 GMT https://validator.w3.org/feed/docs/rss2.html @@ -127,8 +127,8 @@ exports[`rss 2.0 should generate a valid feed with enclosure 1`] = ` 60 Feed Title - http://example.com/image.png - http://example.com/ + http://example.com/image.png?link=sanitized&value=6 + http://example.com/?link=sanitized&value=3 All rights reserved 2013, John Doe Technology @@ -181,7 +181,7 @@ exports[`rss 2.0 should generate a valid feed with image properties 1`] = ` Feed Title - http://example.com/ + http://example.com/?link=sanitized&value=3 This is my personnal feed! Sat, 13 Jul 2013 23:00:00 GMT https://validator.w3.org/feed/docs/rss2.html @@ -190,8 +190,8 @@ exports[`rss 2.0 should generate a valid feed with image properties 1`] = ` 60 Feed Title - http://example.com/image.png - http://example.com/ + http://example.com/image.png?link=sanitized&value=6 + http://example.com/?link=sanitized&value=3 All rights reserved 2013, John Doe Technology diff --git a/src/__tests__/setup.ts b/src/__tests__/setup.ts index 02c333b..bcdd8eb 100644 --- a/src/__tests__/setup.ts +++ b/src/__tests__/setup.ts @@ -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/", + 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 From 1bc36d0cd4779f5a8fb635eb47cef72f58132688 Mon Sep 17 00:00:00 2001 From: Christian Walther Date: Fri, 5 Mar 2021 22:15:16 +0100 Subject: [PATCH 3/3] Fix double escaping of & in Atom feed "self" URL. --- src/atom1.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atom1.ts b/src/atom1.ts index 3bfe29b..2368a53 100644 --- a/src/atom1.ts +++ b/src/atom1.ts @@ -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) } });