From ef5ef6148fc2345b4a4fd2d5e6b775a423f360c3 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2026 16:07:59 +0200 Subject: config: update default URL regex * Allow single-quotes _inside_ URLs (but still not at the end) * Require at least one character inside balanced parenthesis or quotes. Closes #2417 --- config.c | 87 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 44 insertions(+), 43 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 824a4ded..618ee116 100644 --- a/config.c +++ b/config.c @@ -106,6 +106,47 @@ static const uint32_t default_sixel_colors[16] = { 0xffcccccc, }; +static const char *const default_url_regex_string = + "(" + "(" + "(https?://|mailto:|ftp://|file:|ssh:|ssh://|git://|tel:|magnet:|ipfs://|ipns://|gemini://|gopher://|news:)" + "|" + "www\\." + ")" + "(" + /* Safe + reserved + some unsafe characters parenthesis and double quotes omitted (we only allow them when balanced) */ + "[0-9a-zA-Z:/?#@!$&*+,;=.~_%^'\\-]+" + "|" + /* Balanced "(...)". Content is same as above, plus all _other_ characters we require to be balanced */ + "\\([]\\[\"0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]+\\)" + "|" + /* Balanced "[...]". Content is same as above, plus all _other_ characters we require to be balanced */ + "\\[[\\(\\)\"0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]+\\]" + "|" + /* Balanced '"..."'. Content is same as above, plus all _other_ characters we require to be balanced */ + "\"[]\\[\\(\\)0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]+\"" + "|" + /* Balanced "'...'". Content is same as above, plus all _other_ characters we require to be balanced */ + "'[]\\[\\(\\)0-9a-zA-Z:/?#@!$&*+,;=.~_%^\\-]+'" + ")+" + "(" + /* Same as above, except :?!,;.' are excluded */ + "[0-9a-zA-Z/#@$&*+=~_%^\\-]" + "|" + /* Balanced "(...)". Content is same as above, plus all _other_ characters we require to be balanced */ + "\\([]\\[\"0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]+\\)" + "|" + /* Balanced "[...]". Content is same as above, plus all _other_ characters we require to be balanced */ + "\\[[\\(\\)\"0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]+\\]" + "|" + /* Balanced '"..."'. Content is same as above, plus all _other_ characters we require to be balanced */ + "\"[]\\[\\(\\)0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]+\"" + "|" + /* Balanced "'...'". Content is same as above, plus all _other_ characters we require to be balanced */ + "'[]\\[\\(\\)0-9a-zA-Z:/?#@!$&*+,;=.~_%^\\-]+'" + ")" + ")"; + static const char *const binding_action_map[] = { [BIND_ACTION_NONE] = NULL, [BIND_ACTION_NOOP] = "noop", @@ -3654,50 +3695,10 @@ config_load(struct config *conf, const char *conf_path, tokenize_cmdline("xdg-open ${url}", &conf->url.launch.argv.args); { - const char *url_regex_string = - "(" - "(" - "(https?://|mailto:|ftp://|file:|ssh:|ssh://|git://|tel:|magnet:|ipfs://|ipns://|gemini://|gopher://|news:)" - "|" - "www\\." - ")" - "(" - /* Safe + reserved + some unsafe characters parenthesis and double quotes omitted (we only allow them when balanced) */ - "[0-9a-zA-Z:/?#@!$&*+,;=.~_%^\\-]+" - "|" - /* Balanced "(...)". Content is same as above, plus all _other_ characters we require to be balanced */ - "\\([]\\[\"0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]*\\)" - "|" - /* Balanced "[...]". Content is same as above, plus all _other_ characters we require to be balanced */ - "\\[[\\(\\)\"0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]*\\]" - "|" - /* Balanced '"..."'. Content is same as above, plus all _other_ characters we require to be balanced */ - "\"[]\\[\\(\\)0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]*\"" - "|" - /* Balanced "'...'". Content is same as above, plus all _other_ characters we require to be balanced */ - "'[]\\[\\(\\)0-9a-zA-Z:/?#@!$&*+,;=.~_%^\\-]*'" - ")+" - "(" - /* Same as above, except :?!,;. are excluded */ - "[0-9a-zA-Z/#@$&*+=~_%^\\-]" - "|" - /* Balanced "(...)". Content is same as above, plus all _other_ characters we require to be balanced */ - "\\([]\\[\"0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]*\\)" - "|" - /* Balanced "[...]". Content is same as above, plus all _other_ characters we require to be balanced */ - "\\[[\\(\\)\"0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]*\\]" - "|" - /* Balanced '"..."'. Content is same as above, plus all _other_ characters we require to be balanced */ - "\"[]\\[\\(\\)0-9a-zA-Z:/?#@!$&'*+,;=.~_%^\\-]*\"" - "|" - /* Balanced "'...'". Content is same as above, plus all _other_ characters we require to be balanced */ - "'[]\\[\\(\\)0-9a-zA-Z:/?#@!$&*+,;=.~_%^\\-]*'" - ")" - ")"; - - int r = regcomp(&conf->url.preg, url_regex_string, REG_EXTENDED); + + int r = regcomp(&conf->url.preg, default_url_regex_string, REG_EXTENDED); xassert(r == 0); - conf->url.regex = xstrdup(url_regex_string); + conf->url.regex = xstrdup(default_url_regex_string); xassert(conf->url.preg.re_nsub >= 1); } -- cgit v1.3