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 RSS feed not handling None values #569

Merged
merged 1 commit into from
Nov 4, 2023
Merged
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
2 changes: 2 additions & 0 deletions bookmarks/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class FeedContext:


def sanitize(text: str):
if not text:
return ''
# remove control characters
valid_chars = ['\n', '\r', '\t']
return ''.join(ch for ch in text if ch in valid_chars or unicodedata.category(ch)[0] != 'C')
Expand Down
5 changes: 5 additions & 0 deletions bookmarks/tests/test_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from bookmarks.tests.helpers import BookmarkFactoryMixin
from bookmarks.models import FeedToken, User
from bookmarks.feeds import sanitize



def rfc2822_date(date):
Expand Down Expand Up @@ -112,6 +114,9 @@ def test_strip_control_characters(self):
self.assertContains(response, f'<title>test\n\r\ttitle</title>', count=1)
self.assertContains(response, f'<description>test\n\r\tdescription</description>', count=1)

def test_sanitize_with_none_text(self):
self.assertEqual('', sanitize(None))

def test_unread_returns_404_for_unknown_feed_token(self):
response = self.client.get(reverse('bookmarks:feeds.unread', args=['foo']))

Expand Down