From fef97a9a72e19c0825074de8f5e6433dd10007ea Mon Sep 17 00:00:00 2001
From: Nicholas John Koch <koch@njk-it.de>
Date: Wed, 13 May 2020 20:32:35 +0200
Subject: [PATCH] res_musiconhold: Added check for dot character in path of
 playlist entries to avoid warnings

A warning was triggered that there may be a problem regarding file
extension (which is correct and should not be set anyway). The warning
also appeared if there was dot within the path itself.

E.g.
[sales-queue-hold]
mode=playlist
entry=/var/www/domain.tld/moh/funky_music

The music played correctly but you get a warning message.

Now there will be a check if the position of a potential dot character
is after the last position of a slash character. This dot charachter
will be treated as a extension naming. Dots within the path then ignored.

ASTERISK-28892
Reported-By: Nicholas John Koch

Change-Id: I2ec35a613413affbf5fcc01c8c181eba24865b9e
---
 res/res_musiconhold.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index dd9b8a5176..01a14b93fb 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -1087,9 +1087,14 @@ static void moh_parse_options(struct ast_variable *var, struct mohclass *mohclas
 				if (!dup) {
 					continue;
 				}
-				if (ast_begins_with(dup, "/") && strrchr(dup, '.')) {
-					ast_log(LOG_WARNING, "The playlist entry '%s' may include an extension, which could prevent it from playing.\n",
-						dup);
+
+				if (ast_begins_with(dup, "/")) {
+					char *last_pos_dot = strrchr(dup, '.');
+					char *last_pos_slash = strrchr(dup, '/');
+					if (last_pos_dot && last_pos_dot > last_pos_slash) {
+						ast_log(LOG_WARNING, "The playlist entry '%s' may include an extension, which could prevent it from playing.\n",
+							dup);
+					}
 				}
 				AST_VECTOR_APPEND(&mohclass->files, dup);
 			} else {
-- 
GitLab