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

Conversation

cwalther
Copy link

@cwalther cwalther commented Mar 5, 2021

In the <link rel="self"> URL of an Atom 1 feed, a & in the URL is mistakenly escaped twice, appearing as &amp;amp;.

Steps to reproduce:

node -e 'const Feed = require("feed").Feed; console.log((new Feed({feed: "a&b"})).atom1());'

Expected result:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id/>
    <title/>
    <updated>2021-03-05T21:19:20.314Z</updated>
    <generator>https://github.com/jpmonette/feed</generator>
    <link rel="self" href="a&amp;b"/>
</feed>

Actual result:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id/>
    <title/>
    <updated>2021-03-05T21:16:48.247Z</updated>
    <generator>https://github.com/jpmonette/feed</generator>
    <link rel="self" href="a&amp;amp;b"/>
</feed>

The cause is that 50ed093 was overzealous, feeding atomLink through sanitize() twice.

The attached commits add a currently failing test as well as fix. Also, a few tests for the same thing in other URL-typed fields, but these were already handled correctly.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.571% when pulling 1bc36d0 on cwalther:doubleamp into fd77835 on jpmonette:master.

@cwalther
Copy link
Author

cwalther commented Mar 5, 2021

(To be honest, I’m a bit surprised this sanitize() is needed at all. Shouldn’t it be the job of the XML serialization library to correctly encode attributes?)

cwalther added a commit to cwalther/slack-atom-bridge that referenced this pull request Jan 3, 2023
Requires bugfiix jpmonette/feed#145 in feed, replace local patch once released.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants