PHP_HTTP_API char *_http_absolute_url(const char *url TSRMLS_DC)
{
- char *abs = estrdup(url);
- php_url *purl = php_url_parse(abs);
+ char *abs = NULL;
+ php_url *purl = NULL;
- STR_SET(abs, NULL);
+ if (url) {
+ purl = php_url_parse(abs = estrdup(url));
+ STR_SET(abs, NULL);
+ } else {
+ purl = ecalloc(1, sizeof(php_url));
+ }
if (purl) {
http_build_url(0, purl, NULL, NULL, &abs, NULL);
strlcat(*url_str, url->host, HTTP_URL_MAXLEN);
if (url->port) {
- char port_str[6] = {0};
+ char port_str[8] = {0};
- snprintf(port_str, 5, "%d", (int) url->port);
+ snprintf(port_str, lenof(port_str), "%d", (int) url->port);
strlcat(*url_str, ":", HTTP_URL_MAXLEN);
strlcat(*url_str, port_str, HTTP_URL_MAXLEN);
}
phpstr_init(&new_prefix);
if (prefix && prefix_len) {
phpstr_append(&new_prefix, prefix, prefix_len);
- phpstr_appends(&new_prefix, "[");
+ phpstr_appends(&new_prefix, "%5B");
}
phpstr_append(&new_prefix, encoded_key, encoded_len);
efree(encoded_key);
if (prefix && prefix_len) {
- phpstr_appends(&new_prefix, "]");
+ phpstr_appends(&new_prefix, "%5D");
}
phpstr_fix(&new_prefix);
}