Skip to content

Commit

Permalink
Issue #6: deal with relative RSS feed links (see Hacker News).
Browse files Browse the repository at this point in the history
  • Loading branch information
passiomatic committed Mar 14, 2015
1 parent ad885c8 commit 2a10aa9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coldsweat/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def feed_add_1(self):
#return self.respond_with_template('_feed_add_wizard_1.html', locals())

if not sniff_feed(response.text):
links = find_feed_links(response.text)
links = find_feed_links(response.text, base_url=self_link)
return self.respond_with_template('_feed_add_wizard_2.html', locals())

# It's a feed
Expand Down
2 changes: 1 addition & 1 deletion coldsweat/markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def start_base(self, attrs):
d = dict(attrs)
if 'href' not in d:
return
# Override passed base URL
self.base_url = d['href']

def start_link(self, attrs):
Expand All @@ -179,7 +180,6 @@ def start_link(self, attrs):
if 'href' not in d:
return

#@@TODO: check if it's relative URL before join
url, title = urlparse.urljoin(self.base_url, d['href']), d['title'] if 'title' in d else u''
self.links.append((url, title))

Expand Down
1 change: 1 addition & 0 deletions coldsweat/tests/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def run_tests():
('discovery/html5-xhtml.html', 'http://example.com/feed'),
('discovery/xhtml.html', 'http://somedomain.com/articles.xml' ),
('discovery/html4-base.html', 'http://somedomain.com/articles.xml' ),
('discovery/html4-no-base.html', 'http://example.com/articles.xml' ),
]

for filename, expected_url in test_files:
Expand Down
10 changes: 10 additions & 0 deletions coldsweat/tests/discovery/html4-no-base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minimal HTML4 w/out BASE document</title>
<link rel="Alternate" type="application/rss+xml" title="RSS" href="articles.xml">
</head>
<body>
Content here.
</body>
</html>

0 comments on commit 2a10aa9

Please sign in to comment.