From 2023623b1640533da1d8d0178d42c92d1c12532c Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Thu, 6 Mar 2014 18:05:22 +0100 Subject: [PATCH] Fix URL matching regex The URL matching regex as currently used by dust is too liberal, and will just match about anything. Some examples: "establishing connection..." => connection... "setting volume to [50%]" => 50%] The following expression is an adapted copy of urxvt's URL matcher. --- menu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/menu.c b/menu.c index 12e1ae2..90b7095 100644 --- a/menu.c +++ b/menu.c @@ -28,7 +28,9 @@ char *extract_urls(const char *to_match) if (!is_initialized) { char *regex = - "((http[s]?|ftp[s]?)(://))?(www\\.)?[[:alnum:]._-]+\\.[^[:space:].\"<>]{2,}"; + "\\b(https?://|ftps?://|news://|mailto:|file://|www\\.)" + "[[:alnum:]\\-\\@;/?:&=%$.+!*\x27,~#]*" + "(\\([[:alnum:]\\-\\@;/?:&=%$.+!*\x27,~#]*\\)|[[:alnum:]\\-\\@;/?:&=%$+*~])+"; int ret = regcomp(&cregex, regex, REG_EXTENDED | REG_ICASE); if (ret != 0) { printf("failed to compile regex\n");