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:
1 parent
a47ff28ed1
commit
49982c5467
2 files changed
+43
-2
No files matched your search
@@ -54,8 +54,24 @@ class PaywallService {
|
||||
bool isPaid(Article a) =>
|
||||
paidTitle.hasMatch(a.title) || _isCutSubstackPost(a) || (_checks[a.link]?.paid ?? false);
|
||||
|
||||
static bool _isCutSubstackPost(Article a) =>
|
||||
_substackCut.firstMatch(a.contentHtml)?.group(1) == a.link;
|
||||
static bool _isCutSubstackPost(Article a) {
|
||||
final readMore = _substackCut.firstMatch(a.contentHtml)?.group(1);
|
||||
return readMore != null && _samePost(readMore, a.link);
|
||||
}
|
||||
|
||||
/// Whether two links point at the same post. Only host and path count:
|
||||
/// scheme, host case, a trailing slash, the query (tracking parameters)
|
||||
/// and the fragment don't.
|
||||
static bool _samePost(String a, String b) {
|
||||
String? key(String link) {
|
||||
final uri = Uri.tryParse(link.trim());
|
||||
if (uri == null || uri.host.isEmpty) return null;
|
||||
return '${uri.host.toLowerCase()}${uri.path.replaceFirst(RegExp(r'/+$'), '')}';
|
||||
}
|
||||
|
||||
final keyA = key(a);
|
||||
return keyA != null && keyA == key(b);
|
||||
}
|
||||
|
||||
bool isSponsored(Article a) => sponsoredTitle.hasMatch(a.title);
|
||||
|
||||
|
||||
Reference in new issue
Block a user