Skip to content

Commit

Permalink
utils: Make behavior of ast_strsep* match strsep.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jcolp authored and asterisk-org-access-app[bot] committed Feb 6, 2024
1 parent d7583f1 commit edf5495
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/asterisk/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions main/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit edf5495

Please sign in to comment.