From fc2aaa75baff15d201153efeeda0c4c5898e4822 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 25 Jan 2024 18:09:18 -0800 Subject: [PATCH] next_thread should be an absolute URL --- glowfic.py | 4 ++-- glowfic_test.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/glowfic.py b/glowfic.py index 81a5342..9d863c8 100644 --- a/glowfic.py +++ b/glowfic.py @@ -7,7 +7,7 @@ from dataclasses import dataclass import itertools -from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse +from urllib.parse import parse_qsl, urlencode, urljoin, urlparse, urlunparse from typing import Iterable @@ -63,7 +63,7 @@ class Thread: for a in c.findChildren('a'): if 'Next Post' in a.text and 'href' in a.attrs and isinstance( a.attrs['href'], str): - return a.attrs['href'] + return urljoin(spec.url, a.attrs['href']) return None spec.log('Fetching HTML...\r') diff --git a/glowfic_test.py b/glowfic_test.py index 22eea25..bd26e3c 100644 --- a/glowfic_test.py +++ b/glowfic_test.py @@ -103,7 +103,7 @@ class TestThread(unittest.TestCase): ''')) self.assertEqual(t.title(), 'Teh Story!') - def testNextThread(self) -> None: + def testNextThreadRelative(self) -> None: t = Thread(spec_for_testing(b'''
@@ -113,7 +113,19 @@ class TestThread(unittest.TestCase):
The "post"
''')) - self.assertEqual(t.next_thread(), '/posts/4567') + self.assertEqual(t.next_thread(), 'https://fake/posts/4567') + + def testNextThreadAbsolute(self) -> None: + t = Thread(spec_for_testing(b''' + +
+
Next Post »
+
« Previous Post
+
+
+
The "post"
+ ''')) + self.assertEqual(t.next_thread(), 'https://elsewhere/posts/4567') if __name__ == '__main__': -- 2.44.1