]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
utils: Make behavior of ast_strsep* match strsep.
authorJoshua C. Colp <jcolp@sangoma.com>
Wed, 31 Jan 2024 14:03:28 +0000 (10:03 -0400)
committerAsterisk Development Team <asteriskteam@digium.com>
Thu, 7 Mar 2024 14:18:40 +0000 (14:18 +0000)
Given the scenario of passing an empty string to the
ast_strsep functions the functions would return NULL
instead of an empty string. This is counter to how
strsep itself works.

This change alters the behavior of the functions to
match that of strsep.

Fixes: #565
(cherry picked from commit 8ce69eda14c6564240a7f81640c1abad1cb76778)

include/asterisk/strings.h
main/utils.c

index f8ad4140d8fea4d3eca0c5a08f68f05100514c5d..10eb011463803879d790d08f43021b905089eda2 100644 (file)
@@ -271,7 +271,7 @@ enum ast_strsep_flags {
   AST_STRSEP_UNESCAPE unescapes '\' sequences.
   AST_STRSEP_ALL does all of the above processing.
   \return The next token or NULL if done or if there are more than 8 levels of
-  nested quotes.
+  nested quotes. If provided an empty string, will return the empty string.
 
   This function acts like strsep with three exceptions...
   The separator is a single character instead of a string.
@@ -323,7 +323,7 @@ char *ast_strsep(char **s, const char sep, uint32_t flags);
   AST_STRSEP_UNESCAPE unescapes '\' sequences.
   AST_STRSEP_ALL does all of the above processing.
   \return The next token or NULL if done or if there are more than 8 levels of
-  nested quotes.
+  nested quotes. If provided an empty string, will return the empty string.
  */
 char *ast_strsep_quoted(char **s, const char sep, const char quote, uint32_t flags);
 
index b4d79867c9c12762ee9a215d584696f6fa258893..80282308d56df24000937b79269107b8b61aebab 100644 (file)
@@ -1841,7 +1841,8 @@ char *ast_strsep(char **iss, const char sep, uint32_t flags)
        char stack[8];
 
        if (ast_strlen_zero(st)) {
-               return NULL;
+               *iss = NULL;
+               return st;
        }
 
        memset(stack, 0, sizeof(stack));
@@ -1905,7 +1906,8 @@ char *ast_strsep_quoted(char **iss, const char sep, const char quote, uint32_t f
        const char qstr[] = { quote };
 
        if (ast_strlen_zero(st)) {
-               return NULL;
+               *iss = NULL;
+               return st;
        }
 
        memset(stack, 0, sizeof(stack));