URL UTF-8 Bugfix

This commit is contained in:
2021-01-24 21:20:48 +01:00
parent 53fcceeafb
commit b6c7d8f58e
3 changed files with 8 additions and 5 deletions

View File

@ -146,7 +146,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
if (strcmp(uri.uri, buf0) != 0 || change_proto) {
res.status = http_get_status(308);
size = sizeof(buf0);
encode_url(uri.uri, buf0, &size);
url_encode(uri.uri, buf0, &size);
if (change_proto) {
sprintf(buf1, "https://%s%s", host, buf0);
http_add_header_field(&res.hdr, "Location", buf1);

View File

@ -23,7 +23,7 @@ char *format_duration(unsigned long micros, char *buf) {
return buf;
}
int url_encode(const char *str, char *enc, ssize_t *size) {
int url_encode_component(const char *str, char *enc, ssize_t *size) {
char *ptr = enc;
char ch;
memset(enc, 0, *size);
@ -50,7 +50,7 @@ int url_encode(const char *str, char *enc, ssize_t *size) {
return 0;
}
int encode_url(const char *str, char *enc, ssize_t *size) {
int url_encode(const char *str, char *enc, ssize_t *size) {
char *ptr = enc;
unsigned char ch;
memset(enc, 0, *size);
@ -89,6 +89,9 @@ int url_decode(const char *str, char *dec, ssize_t *size) {
buf[2] = 0;
ch = (char) strtol(buf, NULL, 16);
i += 2;
} else if (ch == '?') {
strcpy(ptr, str + i);
break;
}
ptr[0] = ch;
}

View File

@ -22,9 +22,9 @@ char *log_prefix;
char *format_duration(unsigned long micros, char *buf);
int url_encode(const char *str, char *enc, ssize_t *size);
int url_encode_component(const char *str, char *enc, ssize_t *size);
int encode_url(const char *str, char *enc, ssize_t *size);
int url_encode(const char *str, char *enc, ssize_t *size);
int url_decode(const char *str, char *dec, ssize_t *size);