Browse Source

[core] buffer_append_string_encoded() uc hex

Use uc hex chars in buffer_append_string_encoded(), preferred in RFC3986

Preserve behavior using lc hex chars in buffer_append_string_c_escaped()
personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
1593190651
  1. 13
      src/buffer.c
  2. 4
      tests/core-response.t

13
src/buffer.c

@ -7,7 +7,6 @@
#include <string.h>
#include <time.h> /* strftime() */
static const char hex_chars[] = "0123456789abcdef";
static const char hex_chars_lc[] = "0123456789abcdef";
static const char hex_chars_uc[] = "0123456789ABCDEF";
@ -684,16 +683,16 @@ void buffer_append_string_encoded(buffer *b, const char *s, size_t s_len, buffer
case ENCODING_REL_URI:
case ENCODING_REL_URI_PART:
d[d_len++] = '%';
d[d_len++] = hex_chars[((*ds) >> 4) & 0x0F];
d[d_len++] = hex_chars[(*ds) & 0x0F];
d[d_len++] = hex_chars_uc[((*ds) >> 4) & 0x0F];
d[d_len++] = hex_chars_uc[(*ds) & 0x0F];
break;
case ENCODING_HTML:
case ENCODING_MINIMAL_XML:
d[d_len++] = '&';
d[d_len++] = '#';
d[d_len++] = 'x';
d[d_len++] = hex_chars[((*ds) >> 4) & 0x0F];
d[d_len++] = hex_chars[(*ds) & 0x0F];
d[d_len++] = hex_chars_uc[((*ds) >> 4) & 0x0F];
d[d_len++] = hex_chars_uc[(*ds) & 0x0F];
d[d_len++] = ';';
break;
case ENCODING_HTTP_HEADER:
@ -755,8 +754,8 @@ void buffer_append_string_c_escaped(buffer *b, const char *s, size_t s_len) {
break;
default:
d[d_len++] = 'x';
d[d_len++] = hex_chars[((*ds) >> 4) & 0x0F];
d[d_len++] = hex_chars[(*ds) & 0x0F];
d[d_len++] = hex_chars_lc[((*ds) >> 4) & 0x0F];
d[d_len++] = hex_chars_lc[(*ds) & 0x0F];
break;
}
} else {

4
tests/core-response.t

@ -90,14 +90,14 @@ $t->{REQUEST} = ( <<EOF
GET /~test%20ä_ HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/~test%20%c3%a4_/' } ];
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/~test%20%C3%A4_/' } ];
ok($tf->handle_http($t) == 0, 'internal redirect in directory with special characters');
$t->{REQUEST} = ( <<EOF
GET /~test%20ä_?foo HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/~test%20%c3%a4_/?foo' } ];
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME}.':'.$tf->{PORT}.'/~test%20%C3%A4_/?foo' } ];
ok($tf->handle_http($t) == 0, 'internal redirect in directory with special characters + querystring');
## simple-vhost

Loading…
Cancel
Save