|
|
4bb5f0 |
From d1bb7a564e0f92ef2081d3af8b4b7f85a307c38f Mon Sep 17 00:00:00 2001
|
|
|
4bb5f0 |
From: Edward Thomson <ethomson@edwardthomson.com>
|
|
|
4bb5f0 |
Date: Fri, 14 Jun 2019 17:37:22 +0100
|
|
|
4bb5f0 |
Subject: [PATCH] url: treat empty port as default
|
|
|
4bb5f0 |
|
|
|
4bb5f0 |
When parsing URLs, treat an empty port (eg `http://hostname:/`) as if it
|
|
|
4bb5f0 |
were unspecified. RFC 3986 says:
|
|
|
4bb5f0 |
|
|
|
4bb5f0 |
> URI producers and normalizers SHOULD omit the port component and its
|
|
|
4bb5f0 |
> ":" delimiter if port is empty or if its value would be the same as
|
|
|
4bb5f0 |
> that of the scheme's default.
|
|
|
4bb5f0 |
|
|
|
4bb5f0 |
(Emphasis on the "SHOULD" is mine.) This indicates that URIs MAY be
|
|
|
4bb5f0 |
produced with an empty port and the `:` delimiter.
|
|
|
4bb5f0 |
|
|
|
4bb5f0 |
Thus, we stop failing if we end host parsing at the port delimiter.
|
|
|
4bb5f0 |
---
|
|
|
4bb5f0 |
http_parser.c | 1 -
|
|
|
4bb5f0 |
test.c | 25 +++++++++++++++++++------
|
|
|
4bb5f0 |
2 files changed, 19 insertions(+), 7 deletions(-)
|
|
|
4bb5f0 |
|
|
|
4bb5f0 |
diff --git a/http_parser.c b/http_parser.c
|
|
|
4bb5f0 |
index 4896385..7e268d8 100644
|
|
|
4bb5f0 |
--- a/http_parser.c
|
|
|
4bb5f0 |
+++ b/http_parser.c
|
|
|
4bb5f0 |
@@ -2326,7 +2326,6 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
|
|
|
4bb5f0 |
case s_http_host_v6:
|
|
|
4bb5f0 |
case s_http_host_v6_zone_start:
|
|
|
4bb5f0 |
case s_http_host_v6_zone:
|
|
|
4bb5f0 |
- case s_http_host_port_start:
|
|
|
4bb5f0 |
case s_http_userinfo:
|
|
|
4bb5f0 |
case s_http_userinfo_start:
|
|
|
4bb5f0 |
return 1;
|
|
|
4bb5f0 |
diff --git a/test.c b/test.c
|
|
|
4bb5f0 |
index 0140a18..54eca61 100644
|
|
|
4bb5f0 |
--- a/test.c
|
|
|
4bb5f0 |
+++ b/test.c
|
|
|
4bb5f0 |
@@ -2825,6 +2825,25 @@ const struct url_test url_tests[] =
|
|
|
4bb5f0 |
,.rv=0
|
|
|
4bb5f0 |
}
|
|
|
4bb5f0 |
|
|
|
4bb5f0 |
+, {.name="proxy empty port"
|
|
|
4bb5f0 |
+ ,.url="http://hostname:/"
|
|
|
4bb5f0 |
+ ,.is_connect=0
|
|
|
4bb5f0 |
+ ,.u=
|
|
|
4bb5f0 |
+ {.field_set=(1 << UF_SCHEMA) | (1 << UF_HOST) | (1 << UF_PATH)
|
|
|
4bb5f0 |
+ ,.port=0
|
|
|
4bb5f0 |
+ ,.field_data=
|
|
|
4bb5f0 |
+ {{ 0, 4 } /* UF_SCHEMA */
|
|
|
4bb5f0 |
+ ,{ 7, 8 } /* UF_HOST */
|
|
|
4bb5f0 |
+ ,{ 0, 0 } /* UF_PORT */
|
|
|
4bb5f0 |
+ ,{ 16, 1 } /* UF_PATH */
|
|
|
4bb5f0 |
+ ,{ 0, 0 } /* UF_QUERY */
|
|
|
4bb5f0 |
+ ,{ 0, 0 } /* UF_FRAGMENT */
|
|
|
4bb5f0 |
+ ,{ 0, 0 } /* UF_USERINFO */
|
|
|
4bb5f0 |
+ }
|
|
|
4bb5f0 |
+ }
|
|
|
4bb5f0 |
+ ,.rv=0
|
|
|
4bb5f0 |
+ }
|
|
|
4bb5f0 |
+
|
|
|
4bb5f0 |
, {.name="CONNECT request"
|
|
|
4bb5f0 |
,.url="hostname:443"
|
|
|
4bb5f0 |
,.is_connect=1
|
|
|
4bb5f0 |
@@ -3059,12 +3078,6 @@ const struct url_test url_tests[] =
|
|
|
4bb5f0 |
,.rv=1
|
|
|
4bb5f0 |
}
|
|
|
4bb5f0 |
|
|
|
4bb5f0 |
-, {.name="proxy empty port"
|
|
|
4bb5f0 |
- ,.url="http://hostname:/"
|
|
|
4bb5f0 |
- ,.is_connect=0
|
|
|
4bb5f0 |
- ,.rv=1
|
|
|
4bb5f0 |
- }
|
|
|
4bb5f0 |
-
|
|
|
4bb5f0 |
, {.name="CONNECT with basic auth"
|
|
|
4bb5f0 |
,.url="a:b@hostname:443"
|
|
|
4bb5f0 |
,.is_connect=1
|
|
|
4bb5f0 |
--
|
|
|
4bb5f0 |
2.25.1
|
|
|
4bb5f0 |
|