Skip to content

Commit b1ab8cd

Browse files
committed
src/UriSetHostCommon.c: Do not set absolutePath for empty paths when removing host
Fixes uriparser#275.
1 parent 974d508 commit b1ab8cd

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/UriSetHostCommon.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ int URI_FUNC(InternalSetHostMm)(URI_TYPE(Uri) * uri, UriHostType hostType,
166166
if (first == NULL) {
167167
/* Yes, but disambiguate as needed */
168168
if (hadHostBefore == URI_TRUE) {
169-
uri->absolutePath = URI_TRUE;
169+
if (uri->pathHead != NULL) {
170+
uri->absolutePath = URI_TRUE;
171+
}
170172

171173
const UriBool success =
172174
URI_FUNC(EnsureThatPathIsNotMistakenForHost)(uri, memory);

test/SetHostAuto.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ TEST(SetHostAuto, NullValueApplied) {
115115
uriFreeUriMembersA(&uri);
116116
}
117117

118+
TEST(SetHostAuto, NullValueAppliedNoPath) {
119+
UriUriA uri = parseWellFormedUri("https://example.com");
120+
121+
EXPECT_EQ(uriSetHostAutoA(&uri, NULL, NULL), URI_SUCCESS);
122+
123+
assertUriEqual(&uri, "https:");
124+
125+
uriFreeUriMembersA(&uri);
126+
}
127+
128+
TEST(SetHostAuto, NullValueAppliedNoPath2) {
129+
UriUriA uri = parseWellFormedUri("https://example.com?foo=bar");
130+
131+
EXPECT_EQ(uriSetHostAutoA(&uri, NULL, NULL), URI_SUCCESS);
132+
133+
assertUriEqual(&uri, "https:?foo=bar");
134+
135+
uriFreeUriMembersA(&uri);
136+
}
137+
118138
TEST(SetHostAuto, NonNullValueAppliedEmpty) {
119139
UriUriA uri = parseWellFormedUri("scheme://host/path");
120140
const char * const empty = "";

0 commit comments

Comments
 (0)