improve regex to handle :1234 in url

This commit is contained in:
prx 2022-08-18 10:53:08 +02:00
parent 5063f3e95b
commit f388d2a57a
2 changed files with 10 additions and 4 deletions

3
vger.c
View File

@ -527,6 +527,9 @@ split_request(const char *request, char *hostname, char *path, char *query)
getsubexp(request, match[1], hostname); getsubexp(request, match[1], hostname);
getsubexp(request, match[2], path); getsubexp(request, match[2], path);
getsubexp(request, match[3], query); getsubexp(request, match[3], query);
syslog(LOG_DAEMON, "hostname:%s", hostname);
syslog(LOG_DAEMON, "path:%s", path);
syslog(LOG_DAEMON, "query:%s", query);
regfree(&greg); regfree(&greg);
} }

11
vger.h
View File

@ -18,9 +18,11 @@
* ============= * =============
* ^gemini://+ : in case of gemini:/// * ^gemini://+ : in case of gemini:///
* 1: hostname * 1: hostname
* ([^/|^\?]*) : * ([^/|^\?|^:]*) :
* catch everything, stop when / or ? is found * catch everything, stop when /, ? or : is found
* then skip multiple / * don't catch :port
* [:[0-9]*]? : skip :1234 (port number) if any
* / * : skip "/" if any
* 2: path * 2: path
* ([^\?]*) : * ([^\?]*) :
* catch everything and stop at ? if any * catch everything and stop at ? if any
@ -28,7 +30,8 @@
* [\?]?(.*)$: * [\?]?(.*)$:
* catch everything after ? if any * catch everything after ? if any
*/ */
static const char *_gemini_regex = "^gemini://+([^/|^\?]*)/*([^\?]*)[\?]?(.*)$"; static const char *_gemini_regex =
"^gemini://+([^/|^\?|^:]*)[:[0-9]*]?/*([^\?]*)[\?]?(.*)$";
/* global vars */ /* global vars */
static int _retcode = 0; static int _retcode = 0;