Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions proxy/hdrs/URL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <new>
#include "tscore/ink_platform.h"
#include "tscore/ink_memory.h"
#include "tscore/TsBuffer.h"
#include "URL.h"
#include "MIME.h"
#include "HTTP.h"
Expand Down Expand Up @@ -1284,7 +1283,7 @@ url_parse_internet(HdrHeap *heap, URLImpl *url, const char **start, char const *
const char *cur = *start;
const char *base; // Base for host/port field.
const char *bracket = nullptr; // marker for open bracket, if any.
ts::ConstBuffer user, passw, host, port;
swoc::TextView user, passw, host, port;
static size_t const MAX_COLON = 8; // max # of valid colons.
size_t n_colon = 0;
const char *last_colon = nullptr; // pointer to last colon seen.
Expand Down Expand Up @@ -1313,7 +1312,7 @@ url_parse_internet(HdrHeap *heap, URLImpl *url, const char **start, char const *
stripping brackets from non-IPv6 content but that gets ugly
as well. Just not worth it.
*/
host.set(bracket, cur);
host.assign(bracket, cur);
// Spec requires This constitute the entire host so the next
// character must be missing (EOS), slash, or colon.
if (cur >= end || '/' == *cur) { // done which is OK
Expand All @@ -1339,12 +1338,12 @@ url_parse_internet(HdrHeap *heap, URLImpl *url, const char **start, char const *
return PARSE_RESULT_ERROR; // we already got one, or too many colons.
}
if (n_colon) {
user.set(base, last_colon);
passw.set(last_colon + 1, cur);
user.assign(base, last_colon);
passw.assign(last_colon + 1, cur);
n_colon = 0;
last_colon = nullptr;
} else {
user.set(base, cur);
user.assign(base, cur);
}
++cur;
base = cur;
Expand Down Expand Up @@ -1374,36 +1373,36 @@ url_parse_internet(HdrHeap *heap, URLImpl *url, const char **start, char const *
// character past the parse area.

if (user) {
url->set_user(heap, user._ptr, user._size, copy_strings_p);
url->set_user(heap, user.data(), user.size(), copy_strings_p);
if (passw) {
url->set_password(heap, passw._ptr, passw._size, copy_strings_p);
url->set_password(heap, passw.data(), passw.size(), copy_strings_p);
}
}

// @a host not set means no brackets to mark explicit host.
if (!host) {
if (1 == n_colon || MAX_COLON == n_colon) { // presume port.
host.set(base, last_colon);
host.assign(base, last_colon);
} else { // it's all host.
host.set(base, cur);
host.assign(base, cur);
last_colon = nullptr; // prevent port setting.
}
}
if (host._size) {
if (!verify_host_characters || validate_host_name(std::string_view(host._ptr, host._size))) {
url->set_host(heap, host._ptr, host._size, copy_strings_p);
if (!host.empty()) {
if (!verify_host_characters || validate_host_name(host)) {
url->set_host(heap, host.data(), host.size(), copy_strings_p);
} else {
return PARSE_RESULT_ERROR;
}
}

if (last_colon) {
ink_assert(n_colon);
port.set(last_colon + 1, cur);
if (!port._size) {
port.assign(last_colon + 1, cur);
if (port.empty()) {
return PARSE_RESULT_ERROR; // colon w/o port value.
}
url->set_port(heap, port._ptr, port._size, copy_strings_p);
url->set_port(heap, port.data(), port.size(), copy_strings_p);
}
*start = cur;
return PARSE_RESULT_DONE;
Expand Down