Skip to content

Commit 7b389a8

Browse files
committed
[utils] extend urldecode function
1 parent 9043ded commit 7b389a8

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

include/httpserver/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern const char str_applicationoctetstream[];
4343
const char *utils_getmime(const char *path);
4444
void utils_addmime(const char *ext, const char*mime);
4545

46-
char *utils_urldecode(const char *encoded);
46+
char *utils_urldecode(const char *encoded, size_t length);
4747
int utils_searchexp(const char *haystack, const char *needleslist, const char **rest);
4848

4949
struct utils_parsestring_s

src/utils.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ const char *utils_getmime(const char *filepath)
137137
}
138138

139139

140-
char *utils_urldecode(const char *encoded)
140+
char *utils_urldecode(const char *encoded, size_t length)
141141
{
142142
if (encoded == NULL)
143143
return NULL;
144-
int length = strlen(encoded);
144+
if (length == -1)
145+
length = strlen(encoded);
145146
if (length == 0)
146147
return NULL;
147148
char *decoded = calloc(1, length + 1);
@@ -197,7 +198,7 @@ char *utils_urldecode(const char *encoded)
197198
offset = decoded;
198199
}
199200
}
200-
else if (*encoded == '?')
201+
else if (*encoded == '?' || *encoded == '&')
201202
{
202203
break;
203204
}

0 commit comments

Comments
 (0)