Match a paid Substack post's "Read more" link tolerantly (review item 8)

A trailing slash, tracking query, fragment, other scheme or host case on
either link no longer lets a paid post through the paid filter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CedricandClaude Opus 5.5 committed 2026-10-16 16:04:20 +02:00
1 parent a47ff28ed1
commit 49982c5467
2 files changed
+43 -2

No files matched your search

+25
View File
@@ -56,6 +56,31 @@ void main() {
reason: 'a free post ending with the subscribe widget');
});
test('matches the "Read more" link of a paid Substack post to the post despite URL noise',
() async {
final paywall = PaywallService(await _storage(), client: MockClient((_) async => http.Response('', 500)));
Article cutPost({required String link, required String readMore}) => Article(
title: 'A paid post',
link: link,
source: _source(),
contentHtml: '<p>The first paragraph.</p><p><a href="$readMore">Read more</a></p>',
);
const post = 'https://example.substack.com/p/a-paid-post';
expect(paywall.isPaid(cutPost(link: post, readMore: '$post/')), isTrue,
reason: 'trailing slash on the "Read more" link');
expect(paywall.isPaid(cutPost(link: '$post/', readMore: post)), isTrue,
reason: 'trailing slash on the article link');
expect(paywall.isPaid(cutPost(link: post, readMore: '$post?utm_source=substack&utm_medium=email')),
isTrue, reason: 'tracking query on the "Read more" link');
expect(paywall.isPaid(cutPost(link: '$post?utm_campaign=post#footnote-1', readMore: post)), isTrue,
reason: 'query and fragment on the article link');
expect(paywall.isPaid(cutPost(link: post, readMore: 'http://Example.Substack.com/p/a-paid-post')),
isTrue, reason: 'other scheme and host case');
expect(paywall.isPaid(cutPost(link: post, readMore: 'https://example.substack.com/p/another-post')),
isFalse, reason: 'a "Read more" link to a different post');
});
test('checks pages only for flagged sources and remembers results', () async {
final storage = await _storage();
final requested = <String>[];