From bee8691b33e4846aa0efd5f343a63cc695f4c4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Tue, 15 Feb 2022 13:34:04 +0200 Subject: [PATCH 1/1] Empty path normalization was not being applied Solderpunk's November 2021 update to the specification included a recommendation to normalize empty paths to /. IssueID #455 --- src/gmrequest.c | 9 +++++++++ src/gmutil.c | 4 ---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gmrequest.c b/src/gmrequest.c index 82c232e1..603975f0 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c @@ -593,6 +593,15 @@ void setUrl_GmRequest(iGmRequest *d, const iString *url) { the web. */ /* Encode everything except already-percent encoded characters. */ iString *enc = urlEncodeExclude_String(&d->url, "%" URL_RESERVED_CHARS); + /* Normalize empty paths to /. */ { + iUrl parts; + init_Url(&parts, enc); + if (isEmpty_Range(&parts.path) && equalCase_Rangecc(parts.scheme, "gemini") && + parts.path.start) { + /* Normalize to "/" as per specification (November 2021 update). */ + insertData_Block(&enc->chars, parts.path.start - constBegin_String(enc), "/", 1); + } + } set_String(&d->url, enc); delete_String(enc); d->identity = identityForUrl_GmCerts(d->certs, &d->url); diff --git a/src/gmutil.c b/src/gmutil.c index e59e6649..ecfe2128 100644 --- a/src/gmutil.c +++ b/src/gmutil.c @@ -325,10 +325,6 @@ void urlEncodePath_String(iString *d) { return; } if (isEmpty_Range(&url.path)) { - if (equalCase_Rangecc(url.scheme, "gemini") && url.path.start) { - /* Normalize to "/" as per specification (November 2021 update). */ - insertData_Block(&d->chars, url.path.start - constBegin_String(d), "/", 1); - } return; } iString *encoded = new_String(); -- 2.34.1