Skip to content

Commit

Permalink
Fix RSS feed not handling None values (#569)
Browse files Browse the repository at this point in the history
Previously, the 'sanitize' function would throw an error when 'text' was None. This commit fixes the issue by adding a check to handle the case where 'text' is None, returning an empty string instead.

Closes #568
  • Loading branch information
vitormarcal authored Nov 4, 2023
1 parent dc9799c commit 560769f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
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

0 comments on commit 560769f

Please sign in to comment.