From 49731817d10c29646a6eaec17a63fc63a1ce93c7 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 4 Mar 2015 16:00:55 +0000 Subject: [PATCH] Fix match behaviour. --- src/lua/lua_regexp.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index 04f141fb3..84455280f 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -123,14 +123,23 @@ lua_regexp_create (lua_State *L) } } else if (string[0] == 'm') { - /* Special case for perl */ + /* Special case for m */ slash = &string[1]; sep = *slash; - slash = strrchr (string, sep); - if (slash != NULL && slash > &string[1]) { - flags_str = slash + 1; - pattern = g_malloc (slash - string - 1); - rspamd_strlcpy (pattern, string + 2, slash - string - 1); + + if (sep == '\0' || g_ascii_isalnum (sep)) { + /* Not a special case */ + } + else { + slash = strrchr (string, sep); + if (slash != NULL && slash > &string[1]) { + flags_str = slash + 1; + pattern = g_malloc (slash - string + 1); + pattern[0] = '^'; + rspamd_strlcpy (pattern + 1, string + 2, slash - string - 1); + pattern[slash - string - 1] = '$'; + pattern[slash - string] = '\0'; + } } } else { -- 2.39.5