Browse code

core: allow empty matches

Anchors like ^ and $ match beginning resp. ending of strings but their
matches are zero length, which is ok.
The anchors can be used to pre-/append a prefix/suffix via e.g.
subst_hf("X-My-Header", "/^/prefix /", "a");
subst_hf("X-My-Header", "/$/ suffix/", "a");

Bastian Triller authored on 05/10/2021 10:00:36
Showing 2 changed files
... ...
@@ -299,7 +299,7 @@ struct lump* del_lump(struct sip_msg* msg, int offset, int len,
299 299
 		return 0;
300 300
 	}
301 301
 	if (len==0){
302
-		LM_WARN("0 len (offset=%d)\n", offset);
302
+		LM_DBG("0 len (offset=%d)\n", offset);
303 303
 	}
304 304
 
305 305
 	tmp=pkg_malloc(sizeof(struct lump));
... ...
@@ -440,10 +440,6 @@ struct replace_lst* subst_run(struct subst_expr* se, const char* input,
440 440
 				LM_ERR("Unknown offset?\n");
441 441
 				goto error;
442 442
 			}
443
-			if (pmatch[0].rm_so==pmatch[0].rm_eo) {
444
-				LM_ERR("Matched string is empty, invalid regexp?\n");
445
-				goto error;
446
-			}
447 443
 			*crt=pkg_malloc(sizeof(struct replace_lst));
448 444
 			if (*crt==0){
449 445
 				PKG_MEM_ERROR;