From a573d5155d0c9554789124d8d02ed83bd21ec46e Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 12 Jan 2021 12:02:07 +0200 Subject: Feeds: Strip default Gemini ports from URLs --- src/feeds.c | 1 + src/gmutil.c | 10 ++++++++++ src/gmutil.h | 1 + 3 files changed, 12 insertions(+) diff --git a/src/feeds.c b/src/feeds.c index 0f06e33d..75173ee1 100644 --- a/src/feeds.c +++ b/src/feeds.c @@ -509,6 +509,7 @@ static void load_Feeds_(iFeeds *d) { entry->posted.ts.tv_sec = posted; entry->discovered.ts.tv_sec = discovered; set_String(&entry->url, url); + stripDefaultUrlPort_String(&entry->url); set_String(&entry->title, title); insert_SortedArray(&d->entries, &entry); } diff --git a/src/gmutil.c b/src/gmutil.c index a299347f..ab9a8eea 100644 --- a/src/gmutil.c +++ b/src/gmutil.c @@ -81,6 +81,16 @@ static iRangecc prevPathSeg_(const char *end, const char *start) { return seg; } +void stripDefaultUrlPort_String(iString *d) { + iUrl parts; + init_Url(&parts, d); + if (equalCase_Rangecc(parts.scheme, "gemini") && equal_Rangecc(parts.port, "1965")) { + /* Always preceded by a colon. */ + remove_Block(&d->chars, parts.port.start - 1 - constBegin_String(d), + size_Range(&parts.port) + 1); + } +} + void cleanUrlPath_String(iString *d) { iString clean; init_String(&clean); diff --git a/src/gmutil.h b/src/gmutil.h index a9c8c42a..947ff56b 100644 --- a/src/gmutil.h +++ b/src/gmutil.h @@ -104,6 +104,7 @@ iRangecc urlScheme_String (const iString *); iRangecc urlHost_String (const iString *); const iString * absoluteUrl_String (const iString *, const iString *urlMaybeRelative); void punyEncodeUrlHost_String(iString *); +void stripDefaultUrlPort_String(iString *); void urlDecodePath_String (iString *); void urlEncodePath_String (iString *); iString * makeFileUrl_String (const iString *localFilePath); -- cgit v1.2.3