Add url_decode_field

This commit is contained in:
2025-12-06 01:27:31 +01:00
parent bc5679aa11
commit a409997006
2 changed files with 33 additions and 0 deletions
+31
View File
@@ -901,3 +901,34 @@ int url_remove_white_space(char *src, int len, char *dst, int cap)
return copied;
}
int url_decode_field(URL_String field, char *dst, int cap)
{
char *src = field.ptr;
int len = field.len;
int rd = 0;
int wr = 0;
while (rd < len) {
int ret = is_percent_encoded(src, len, rd);
if (ret < 0)
return -1;
char c;
if (ret == 1) {
int h = hex_digit_to_int(src[rd+1]);
int l = hex_digit_to_int(src[rd+2]);
c = (char) ((h << 4) | l);
rd += 3;
} else {
c = src[rd];
rd++;
}
if (wr < cap)
dst[wr] = c;
wr++;
}
return wr;
}
+2
View File
@@ -110,4 +110,6 @@ int url_resolve_reference(char *src, int len, int *pcur,
int url_remove_white_space(char *src, int len, char *dst, int cap);
int url_decode_field(URL_String field, char *dst, int cap);
#endif // URL_INCLUDED