From 6f26ecb734d1caa50ca47ceb4700236f3638cf33 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 4 May 2026 10:28:10 +0200 Subject: [PATCH] tool_formparse: cleanups - explain the get_param_part() function - make it parse only blanks like the rest of this code - check for commas explicitly when scanning multiple files (to help code understanding) Closes #21489 --- src/tool_formparse.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/tool_formparse.c b/src/tool_formparse.c index eb43b06ed9..b8161813b0 100644 --- a/src/tool_formparse.c +++ b/src/tool_formparse.c @@ -596,13 +596,40 @@ static void param_encoder(char **ptr, char **endct, char **pencoder, *pencoder = get_param_word(&p, &endpos, endchar); /* If not quoted, strip trailing spaces. */ if(*pencoder == tp) - while(endpos > *pencoder && ISSPACE(endpos[-1])) + while(endpos > *pencoder && ISBLANK(endpos[-1])) endpos--; *sep = *p; *endpos = '\0'; *ptr = p; } +/** + * Parses a single parameter part and its associated metadata from a string. + * + * This function extracts a primary data word and scans for optional + * semicolon-separated attributes including 'type=', 'filename=', 'headers=', + * and 'encoder='. + * + * Used for parsing command-line form arguments or multipart/form-data + * attributes. + * + * @param endchar The character that signifies the end of the entire + * parameter block (e.g., ',' or '\0'). + * @param str Pointer to the current position in the input string. + * Updated to point at the delimiter or terminator that + * ended the parsed part. + * @param pdata Pointer to a char * that will receive the primary data + * word. + * @param ptype [out] Optional. Receives the extracted 'type=' value. + * @param pfilename [out] Optional. Receives the extracted 'filename=' value. + * @param pencoder [out] Optional. Receives the extracted 'encoder=' value. + * @param pheaders [out] Optional. Receives a pointer to a curl_slist + * containing extracted 'headers='. + * + * @return The character that terminated the parsing (casted to int), + * or -1 on memory or parsing error. + */ + static int get_param_part(char endchar, char **str, char **pdata, char **ptype, char **pfilename, char **pencoder, @@ -865,7 +892,7 @@ int formparse(const char *input, SET_TOOL_MIME_PTR(part, encoder); /* *contp could be '\0', so we check with the delimiter */ - } while(sep); /* loop if there is another filename */ + } while(sep == ','); /* loop if there is another filename */ part = (*mimecurrent)->subparts; /* Set name on group. */ } else {