From 5b7d068a4b1be3d8ddaf2cfa0a6998313e511d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Mon, 28 Dec 2020 19:33:20 +0100 Subject: [PATCH] Fix --accept-regex/i--reject-regex for FTP * src/ftp.c (ftp_retrieve_glob): Call accept_url() with the full URL Reported-by: Frans de Boer --- src/ftp.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/ftp.c b/src/ftp.c index 37811451..a44bf04b 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -2660,11 +2660,30 @@ ftp_retrieve_glob (struct url *u, struct url *original_url, continue; } - if (!accept_url (f->name)) + if (opt.acceptregex || opt.rejectregex) { - logprintf (LOG_VERBOSE, _("%s is excluded/not-included through regex.\n"), f->name); - f = delelement (&f, &start); - continue; + // accept_url() takes the full URL. + char buf[1024]; + char *url = buf; + + if ((unsigned) snprintf(buf, sizeof(buf), "%s%s%s", + u->url, f->name, f->type == FT_DIRECTORY ? "/" : "") + >= sizeof(buf)) + { + url = aprintf("%s%s%s", u->url, f->name, f->type == FT_DIRECTORY ? "/" : ""); + } + + if (!accept_url (url)) + { + logprintf (LOG_VERBOSE, _ ("%s is excluded/not-included through regex.\n"), url); + f = delelement (&f, &start); + if (url != buf) + xfree(url); + continue; + } + + if (url != buf) + xfree(url); } /* Now weed out the files that do not match our globbing pattern.