Add PR #3370 patch to not truncate octets after `?' in gopher:// URLs - pkgsrc-localpatches - leot's pkgsrc LOCALPATCHES
 (HTM) hg clone https://bitbucket.org/iamleot/pkgsrc-localpatches
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) changeset 21a516e29e2f07e812d92885681f7791c512eba9
 (DIR) parent 3e5eae85f6fe20dff658bbf1e5ed9db5442164ae
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Thu, 13 Dec 2018 02:05:33 
       
       Add PR #3370 patch to not truncate octets after `?' in gopher:// URLs
       
       Diffstat:
        www/curl/patch-3370.patch |  121 ++++++++++++++++++++++++++++++++++++++++++++++
        1 files changed, 121 insertions(+), 0 deletions(-)
       ---
       diff -r 3e5eae85f6fe -r 21a516e29e2f www/curl/patch-3370.patch
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/www/curl/patch-3370.patch Thu Dec 13 02:05:33 2018 +0100
       @@ -0,0 +1,121 @@
       +Permit to semantically distinguish URL with empty query (closes #3369)
       +
       +In the URL API there is no way to distinguish URL with possible
       +trailing `?' (empty query).
       +
       +This is needed for e.g. in the gopher:// scheme where
       +<gopher://host/1/foo> and <gopher://host/1/foo?>.
       +can be two different URLs.
       +
       +Adjust gopher too in order to not ignore the "query" part and modify
       +the selector in the gopher selector test (`test1201`) to test for
       +that.
       +
       +Closes #3369
       +
       + <https://github.com/curl/curl/pull/3370>
       +
       +diff --git a/lib/gopher.c b/lib/gopher.c
       +index b441a641d9..151bac1adb 100644
       +--- lib/gopher.c.orig
       ++++ lib/gopher.c
       +@@ -31,9 +31,11 @@
       + #include "progress.h"
       + #include "gopher.h"
       + #include "select.h"
       ++#include "strdup.h"
       + #include "url.h"
       + #include "escape.h"
       + #include "warnless.h"
       ++#include "curl_printf.h"
       + #include "curl_memory.h"
       + /* The last #include file should be: */
       + #include "memdebug.h"
       +@@ -78,7 +80,9 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
       +   curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
       + 
       +   curl_off_t *bytecount = &data->req.bytecount;
       ++  char *gopherpath;
       +   char *path = data->state.up.path;
       ++  char *query = data->state.up.query;
       +   char *sel = NULL;
       +   char *sel_org = NULL;
       +   ssize_t amount, k;
       +@@ -86,8 +90,16 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
       + 
       +   *done = TRUE; /* unconditionally */
       + 
       ++  if(path && query)
       ++    gopherpath = aprintf("%s?%s", path, query);
       ++  else
       ++    gopherpath = strdup(path);
       ++
       ++  if(!gopherpath)
       ++    return CURLE_OUT_OF_MEMORY;
       ++
       +   /* Create selector. Degenerate cases: / and /1 => convert to "" */
       +-  if(strlen(path) <= 2) {
       ++  if(strlen(gopherpath) <= 2) {
       +     sel = (char *)"";
       +     len = strlen(sel);
       +   }
       +@@ -95,11 +107,12 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
       +     char *newp;
       + 
       +     /* Otherwise, drop / and the first character (i.e., item type) ... */
       +-    newp = path;
       ++    newp = gopherpath;
       +     newp += 2;
       + 
       +     /* ... and finally unescape */
       +     result = Curl_urldecode(data, newp, 0, &sel, &len, FALSE);
       ++    free(gopherpath);
       +     if(result)
       +       return result;
       +     sel_org = sel;
       +diff --git a/lib/urlapi.c b/lib/urlapi.c
       +index e68748818c..6919ff1bd7 100644
       +--- lib/urlapi.c.orig
       ++++ lib/urlapi.c
       +@@ -864,7 +864,7 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
       +       return CURLUE_OUT_OF_MEMORY;
       +   }
       + 
       +-  if(query && query[0]) {
       ++  if(query) {
       +     u->query = strdup(query);
       +     if(!u->query)
       +       return CURLUE_OUT_OF_MEMORY;
       +@@ -1071,8 +1071,8 @@ CURLUcode curl_url_get(CURLU *u, CURLUPart what,
       +                     port ? port : "",
       +                     (u->path && (u->path[0] != '/')) ? "/": "",
       +                     u->path ? u->path : "/",
       +-                    u->query? "?": "",
       +-                    u->query? u->query : "",
       ++                    (u->query && u->query[0]) ? "?": "",
       ++                    (u->query && u->query[0]) ? u->query : "",
       +                     u->fragment? "#": "",
       +                     u->fragment? u->fragment : "");
       +     }
       +diff --git a/tests/data/test1201 b/tests/data/test1201
       +index 81a9fe4250..29a059aa07 100644
       +--- tests/data/test1201.orig
       ++++ tests/data/test1201
       +@@ -25,7 +25,7 @@ gopher
       + Gopher selector
       +  </name>
       +  <command>
       +-gopher://%HOSTIP:%GOPHERPORT/1/selector/SELECTOR/1201
       ++gopher://%HOSTIP:%GOPHERPORT/1/selector/SELECTOR/1201?
       + </command>
       + </client>
       + 
       +@@ -33,7 +33,7 @@ gopher://%HOSTIP:%GOPHERPORT/1/selector/SELECTOR/1201
       + # Verify data after the test has been "shot"
       + <verify>
       + <protocol>
       +-/selector/SELECTOR/1201
       ++/selector/SELECTOR/1201?
       + </protocol>
       + </verify>
       + </testcase>