From 10657f3f5c1fb00d6b8e85d3956c170695b169bd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 2 Oct 2012 11:56:21 -0500 Subject: [PATCH] FS-4675 --resolve --- .../applications/mod_commands/mod_commands.c | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index d823af7194..892d6e7479 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -1563,15 +1563,19 @@ SWITCH_STANDARD_API(regex_function) proceed = switch_regex_perform(argv[0], argv[1], &re, ovector, sizeof(ovector) / sizeof(ovector[0])); if (argc > 2) { - len = (strlen(argv[0]) + strlen(argv[2]) + 10) * proceed; - substituted = malloc(len); - switch_assert(substituted); - memset(substituted, 0, len); - switch_replace_char(argv[2], '%', '$', SWITCH_FALSE); - switch_perform_substitution(re, proceed, argv[2], argv[0], substituted, len, ovector); + if (proceed) { + len = (strlen(argv[0]) + strlen(argv[2]) + 10) * proceed; + substituted = malloc(len); + switch_assert(substituted); + memset(substituted, 0, len); + switch_replace_char(argv[2], '%', '$', SWITCH_FALSE); + switch_perform_substitution(re, proceed, argv[2], argv[0], substituted, len, ovector); - stream->write_function(stream, "%s", substituted); - free(substituted); + stream->write_function(stream, "%s", substituted); + free(substituted); + } else { + stream->write_function(stream, "%s", argv[0]); + } } else { stream->write_function(stream, proceed ? "true" : "false"); }