lynx gopher telnet item fix

Ben Collver <[email protected]>
Newsgroups gmane.comp.web.lynx.devel
Message-ID <20250107015151.GA1827@rainbow>
Good day,

The current version of lynx cannot open the telnet link in the following
gopher menu.

gopher://mud.nemesis.de/1

When the selector is empty, lynx uses a format with the wrong number
of arguments.

From lynx2.9.2/WWW/Library/Implementation/HTGopher.c:

    const char *format = *selector ? "%s//%s@%s/" : "%s//%s/";
    ...
    HTSprintf0(&address, format, STR_TELNET_URL, selector, host);

The problem happens when the format calls for 2 arguments, but lynx
passes it 3.  Consequently, it ignores the host in the 3rd argument
and this results in a broken telnet item.

Attached is a patch to fix this problem.

This patch changes the format to always use four arguments.  When the
selector is empty, then both the selector and the following argument
are empty strings.  When the selector is not empty, then the selector
is followed by "@".

Best regards,
-Ben
lynx-gopher-telnet-item.diff (text/plain, 1008 B)
--- lynx2.9.2/WWW/Library/Implementation/HTGopher.c.orig	2022-03-31 17:18:09.000000000 -0700
+++ lynx2.9.2/WWW/Library/Implementation/HTGopher.c	2025-01-06 17:49:44.268111625 -0800
@@ -373,18 +373,20 @@
 		       (gtype != GOPHER_DUPLICATE ||
 			this_type != GOPHER_ERROR)) {
 		char *address = 0;
-		const char *format = *selector ? "%s//%s@%s/" : "%s//%s/";
+		const char *format = "%s//%s%s%s/";
 
 		if (gtype == GOPHER_TELNET) {
 		    PUTS(" (TEL) ");
 		    if (*selector == '/')
 			++selector;
-		    HTSprintf0(&address, format, STR_TELNET_URL, selector, host);
+		    HTSprintf0(&address, format, STR_TELNET_URL,
+			       selector, (*selector ? "@" : ""), host);
 		} else if (gtype == GOPHER_TN3270) {
 		    PUTS("(3270) ");
 		    if (*selector == '/')
 			++selector;
-		    HTSprintf0(&address, format, STR_TN3270_URL, selector, host);
+		    HTSprintf0(&address, format, STR_TN3270_URL,
+			       selector, (*selector ? "@" : ""), host);
 		} else {	/* If parsed ok */
 		    char *r;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.